Session_ID not being consistently retrieved

Discussion in 'PHP' started by Darden12, Nov 24, 2008.

  1. #1
    I have a session_ID problem that does not seem to be discussed on the Web.
    The following script will correctly echo "Session ID found" when the following lines are run as part of a page I've called article.php. However, when I run the exact same script on the exact same browser in a different file (something like counthits.php) the script echoes "Session ID not found"!

    How can this be? It happens both on Firefox and on Safari. Both will recognize my session ID when this script below is used in the article.php file, but won't recognize my session ID when the same script is used as part of my counthits.php file.

    Many thanks in advance for any clues as to why I'm getting these Twilight Zone results!

    if ($_SESSION['identifier'] == "Brian") {
     
    
    echo "Session ID found";
    
    } else {
    
    echo "Session ID not found";
    
    }
    PHP:
     
    Darden12, Nov 24, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Are you using session_start() on the first line of counthits.php?
     
    mwasif, Nov 26, 2008 IP
  3. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Yes, I'm using session_start(), thanks. I'm going to check my code again though. I think I must have different versions of a page in two separate directories.
     
    Darden12, Nov 26, 2008 IP
  4. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #4
    We could help you better if you post the two different pages for us to analyze. That is, if you feel comfortable doing so.
     
    qualityfirst, Nov 26, 2008 IP
  5. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #5
    I guess you forgot to call session_start() in some pages.
     
    xrvel, Nov 27, 2008 IP