Problem with session variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stathisgotsis@hotmail.com

    Problem with session variable

    I am building a site and i want to password protect some pages. In
    order to do this i use this variable: $_SESSION['validated'] and i set
    it to true when a user has logged in. So in one file when a user has
    logged in i have the following:
    <?php
    @session_start( );
    $_SESSION['validated']=true;

    ?>
    I am trying to check if this variable is set to true in some other file
    like this:
    <?php
    @session_start( );
    if ( isset($_SESSION['validated']) && $_SESSION['validated']==true )
    {
    /*Something*/
    }
    else
    {
    /*Do something else*/
    }
    ?>
    The problem is it seems i cannot access the $_SESSION['validated'] in
    other files than the one i set it. What is the solution to this
    problem? Please help

  • fletch

    #2
    Re: Problem with session variable

    I bet the session is not being started. Remove the @ infront of
    session_start() and report back if there are any errors. For the
    session stuff to work the headers need to be set. So if you are
    printing anything out before the session_start() then it fails. That
    even includes any space between the begining of a file and the <?.

    Comment

    Working...