Page 1 of 1

how maintain sessions

Posted: Wed Mar 04, 2009 5:05 am
by naeem1984
i wrote the following code in page

login.php

Code: Select all

 
        session_start();
        $_SESSION["username"];
        $username = $_POST['username'];
 
and accesing the session variable value in page

default.php

Code: Select all

 
    session_start();
    echo "Welcome ".$_SESSION[user];
 
but the above code never show the out put
"WELCOME Admin"

what's a matter

Re: how maintain sessions

Posted: Wed Mar 04, 2009 5:50 am
by ben.artiss
You've set $_SESSION['username'] in your login.php and called $_SESSION['user'] in your default.php. Make sure they match and it will work - easy mistake! :)

Re: how maintain sessions

Posted: Wed Mar 04, 2009 6:05 am
by naeem1984
now that mistake was removed but it is still not working.

Re: how maintain sessions

Posted: Wed Mar 04, 2009 6:07 am
by papa
You need to assign a value to the session var on login.php

Code: Select all

session_start();
$username = $_POST['username'];
$_SESSION['username'] = $username;