session variable

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
beckbapegeneral
Forum Newbie
Posts: 19
Joined: Mon May 08, 2006 8:59 pm

session variable

Post by beckbapegeneral »

hi

i need help in sessioning userid. the user is to login and i am to session the userid so that it can be use everywhere in the websites till the user log off. can someone please help
lostinfog
Forum Newbie
Posts: 8
Joined: Wed Apr 26, 2006 4:22 am

Post by lostinfog »

I just use the same solution in my own site.

Before every session superglobal operation, call:
session_start().

When login,

Code: Select all

session_start();
$_SESSION['user_id'] = xxx;
In other pages,

Code: Select all

session_start();
if (isset($_SESSION['user_id'])) {
   ...
} else {
   ...
}
When logout:

Code: Select all

session_start();
unset($_SESSION['user_id']);
beckbapegeneral
Forum Newbie
Posts: 19
Joined: Mon May 08, 2006 8:59 pm

Post by beckbapegeneral »

thanks alot for the help :D
Post Reply