Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Posts
    158
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Session Question

    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:

    PHP 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:

    PHP Code:
    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?

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
    session_name('sn_user2'); session_register('sn_user2'); $_SESSION['sn_user2'] = $userid
    All you need is:

    PHP Code:
    $_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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •