...

View Full Version : Session Question



keith1995
11-07-2007, 09:46 PM
We are developing a site for a client which has a members only section. Once a user logs into the members only section, the left navigation is updated with the members nav beneath the regular nav. I have hardcoded this navigation into the members only pages however we need to carry this nav across to the public pages if a logged in user navigates to one of those pages.

Currently when a user logs in, a session is registered with the following code:


session_name('sn_user2'); session_register('sn_user2'); $_SESSION['sn_user2'] = $userid;

The $userid value is gotten from the database based on the user's login credentials (username/password).

The problem I'm having is that after a user logs in, if they navigate to one of the public pages the member nav disappears. I had thought I could use code such as below to check the session:


if (isset($_SESSION['sn_user2'])) {

If I'm not mistaken, doesn't this code check to see if the session exists and if so, do the actions thereafter, which in this case are to display the member nav.

Is there something I need to be doing before this code to carry/pass the session variables?

aedrin
11-07-2007, 10:07 PM
session_name('sn_user2'); session_register('sn_user2'); $_SESSION['sn_user2'] = $userid;


All you need is:


$_SESSION['sn_user2'] = $userid;

The other function calls are deprecated.


If I'm not mistaken, doesn't this code check to see if the session exists and if so, do the actions thereafter, which in this case are to display the member nav.

Correct. Make sure your session_start() call exists on all pages that you need this on.


hardcoded

This always gives me the shivers. ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum