SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php login script

    hi

    i have been having this strange problem with my session handling script . i have the following code in my login script
    (i have shown only relevant script)

    1) //--login.php

    session_start();
    session_register("userid");
    session_encode();
    $url = "Location: main.php?PHPSESSID=".$PHPSESSID;
    header($url);


    2) //---and in the subsequent pages i check for session is registered or not with the following script

    session_start();
    if (!(session_is_registered("userid")))
    {
    session_unset();
    session_destroy();
    $url = "Location: login.php";
    header($url);
    }
    else
    {

    //--- will open the page successfully

    }


    but the second piece of code doesnt seem to be recognising the session as registered even though the session is registered .

    i dont kno what the problem. could somebody help me pls?

  2. #2
    - Michael - Bytecon's Avatar
    Join Date
    Mar 2004
    Location
    Ireland
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is session_start(); at the very top of each page? i.e. Before any HTML output .. headers etc

  3. #3
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer a combination of:

    PHP Code:
     session_start();
     
    $_SESSION['userid'] = ''// anything
     
     //...
     
     
    if (!isset($_SESSION['userid']))
     {
     
    //...
     
    }
     else
     {
     
    //...
     

    My name is Steve, and I'm a super-villian.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes the session _start() is at the top

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx steve
    your solution worked

    session_start();
    $_SESSION['userid'] = ''; // anything

    although this is much older method of session mgmt , this works better. I hope they dont deprecate it in future versions.

  6. #6
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shiv_sms
    thanx steve
    your solution worked

    session_start();
    $_SESSION['userid'] = ''; // anything

    although this is much older method of session mgmt , this works better. I hope they dont deprecate it in future versions.
    Hi -- not sure why everyone thinks my name is *actually* Steve... maybe I should include a URL...

    And no, this isn't a much older version of session management:

    Quote Originally Posted by php.net/session
    Note: As of PHP 4.1.0, $_SESSION is available as a global variable just like $_POST, $_GET, $_REQUEST and so on. Unlike $HTTP_SESSION_VARS, $_SESSION is always global. Therefore, you do not need to use the global keyword for $_SESSION. Please note that this documentation has been changed to use $_SESSION everywhere. You can substitute $HTTP_SESSION_VARS for $_SESSION, if you prefer the former. Also note that you must start your session using session_start() before use of $_SESSION becomes available.
    My name is Steve, and I'm a super-villian.


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
  •