Session Question

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
curseofthe8ball
Forum Commoner
Posts: 73
Joined: Sun Jun 01, 2003 12:33 am

Session Question

Post by curseofthe8ball »

We are developing a site for a client in which they have a members only section. Upon logging into the members section, the left navigation on the site is updated to add the members nav elements to it. I can handle the login fine and the navigation between members pages is fine but when the user navigates to a page that is a public page, the member nav disappears.

Obviously I'm not carrying the session variables across pages but I'm not sure how to solve this.

When a user logs into the members section, I'm using the following code to register the session:

Code: Select all

session_name('sn_user2'); session_register('sn_user2'); $_SESSION['sn_user2'] = $userid;
The $userid value is pulled from the database which matches the users login credentials (username/password).

What do I need to do on the public pages to check for the session? I thought I just needed to use some code like this:

Code: Select all

if (isset($_SESSION['sn_user2'])) {
If I'm not mistaken, doesn't this code check to see if the session exists and then if so, do the actions following, which in this case would be to display the member nav. Is there something I need to do before this to carry the session variables across pages?
Post Reply