how maintain sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naeem1984
Forum Newbie
Posts: 10
Joined: Thu Feb 26, 2009 3:55 am

how maintain sessions

Post 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
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: how maintain sessions

Post 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! :)
naeem1984
Forum Newbie
Posts: 10
Joined: Thu Feb 26, 2009 3:55 am

Re: how maintain sessions

Post by naeem1984 »

now that mistake was removed but it is still not working.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: how maintain sessions

Post 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;
Post Reply