问题描述:

i want to show the name of user who recently registered on my site ,the username is to be displayed on next linked page ,i am using the following code but it is only displaying welcome

<?php

echo "<h3>Welcome&nbsp;&nbsp;&nbsp;".$_SESSION['fullname']."</h3>";

?>

网友答案:

At login page start session

session_start();

then assign value to this session like

$_SESSION['fullname'] = $_REQUEST['fullname'];

Then on next page also start session

 session_start();

then use your code

echo "<h3>Welcome&nbsp;&nbsp;&nbsp;".$_SESSION['fullname']."</h3>";
网友答案:

on first page that is registration page and also on login page at the top on very first line paste the following line of code

session_start();

after successful registration or login assign some value to session variable

$_SESSION['fullname']=$_POST['fullname'];//this may be getched from DB or form post

now you will be able to get this $_SESSION['fullname'] an any page but remember, session variables are only available if you have started session at top of page. means on any page you want to display user fullname just write it as below.

//at first line of page
session_start();
//your html/js/css code

//where ever you want to display fullname write it as below
echo "Welcome ".$_SESSION['fullname']."!";
//your more html/js/css code

hope this will help you

EDITED write these 2 lines at top of next page

session_start();
print_r($_SESSION);

it will display you all session variables. this way you can start debugging your session variables

网友答案:

You can try this:-

1) Root PHP file in add this.

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
        ob_start("ob_gzhandler");
}
else
{
        ob_start();
}
session_set_cookie_params(0);
session_start();

//set the level of error reporting
//error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
error_reporting(0);

2) other page in "SESSION" Add.

$_SESSION['fullname'] = "Fullname";

3) You can check other page "SESSION"

echo $_SESSION['fullname'];
相关阅读:
Top