SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session variables??

    i've a question about session variables...

    i've this function which will display a Control Panel indicating that the user has logged in... immediately upon a successful login, i register the id (admin_id) as a session var and try to display the control panel... however, when i try to echo $HTTP_SESSION_VARS["admin_id"], nothing appears... it only appears when i refresh... i thought this only happened when you use cookies... do session vars require a page refresh to be accessible too?

    also, i find that it is neccessary to register $HTTP_POST_VARS as a global variable to be able to access the array within a function

    PHP Code:
    else
    // authentication successful: show page contents
    {
        
    $admin_id=$HTTP_POST_VARS["admin_id"];

        
    session_register("admin_id");
        
    session_register("LOGGED");
        
    // the session variable $HTTP_SESSION_VARS
            // ["LOGGED"] will indicate that
        // user is logged in as administrator

        
    display_cpanel();

    this is the function display_cpanel()...
    PHP Code:
    function display_cpanel()
    {
        global $HTTP_SESSION_VARS;
    ?>
    Logged in as 
    <?php echo "<span class=\"admin_id\">".$HTTP_SESSION_VARS["admin_id"]."</span>\n"?>
    <?php
    }// end display_cpanel()
    thanks for any help... i'll be very thankful ... i spent an hour trying to figure this out but to no avail...
    Last edited by redemption; Jan 15, 2002 at 00:56.

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please can someone explain this to me... don't be intimidated by the fact that you've to scroll the page a few times to read the question... pretty please??

    thanks!

  3. #3
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might need to refresh the page...
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  4. #4
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but why?? i figured that when you session_register() a variable it immediately becomes available in the $HTTP_SESSION_VARS array...

  5. #5
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    on the page where you are displaying the data, did you run session_start() ? Everypage that is in the session should have session_start()

    Try that.

  6. #6
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, do display the HTTP_SESSION_VARS without having to make them global change your code a little to look like this:

    PHP Code:
    <?php
    else
    // authentication successful: show page contents
    {
        
    $admin_id=$HTTP_POST_VARS["admin_id"];

        
    session_register("admin_id");
        
    session_register("LOGGED");
        
    // the session variable $HTTP_SESSION_VARS
            // ["LOGGED"] will indicate that
        // user is logged in as administrator

        
    display_cpanel($HTTP_SESSON_VARS);
    }
    ?>
    And

    PHP Code:
    <?php
    function display_cpanel($vars)
    {
    ?>
    Logged in as 
    <?php echo "<span class=\"admin_id\">".$vars["admin_id"]."</span>\n"?>
    <?php
    }
    // end display_cpanel()
    I could help you better if you would show more code, I'm not sure that you are starting the session right and registering correctly.

  7. #7
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before:
    PHP Code:
    else
    // authentication successful: show page contents
    {
        
    $admin_id=$HTTP_POST_VARS["admin_id"];

        
    session_register("admin_id");
        
    session_register("LOGGED");
        
    // the session variable $HTTP_SESSION_VARS
            // ["LOGGED"] will indicate that
        // user is logged in as administrator

        
    display_cpanel();

    Try This:
    PHP Code:
    else
    // authentication successful: show page contents
    {
        
    $admin_id=$HTTP_POST_VARS["admin_id"];
        
    // added line below :)
        
    session_start();
        
    session_register("admin_id");
        
    session_register("LOGGED");
        
    // the session variable $HTTP_SESSION_VARS
            // ["LOGGED"] will indicate that
        // user is logged in as administrator

        
    display_cpanel();

    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  8. #8
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all the replies... the problem is that i do have session_start() at the beginning of the script...

    and i indicate $HTTP_SESSION_VARS as global becos i found that i had to do that with $HTTP_POST_VARS to access them in a function... not sure for session vars though cos i never tested... will try that...

  9. #9
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still doesn't work


Bookmarks

Posting Permissions

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