Results 1 to 6 of 6

Thread: Problem with $_SESSION

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Problem with $_SESSION

    I have a PHP page with an HTML form that checks a users username and password using a MySQL connection, and if they are correct stores them in the $_SESSION cookie. Then the browser is redirected to the home page 'index.php' where the $_SESSION variables are successfully retrieved and the user is shown as logged in.

    However, when I move to another PHP page that uses exactly the same code to access $_SESSION, it cannot find the variables. If I go back to 'index.php', and even refresh the page, it still says logged in. Another website I've built (same server, different directory) functions fine using $_SESSION.

    What the hell is going on? Cookies are definitely enabled, $_SESSION is definitely being set, all pages have 'session_start();' but I can only get to it from one webpage.

    Any help much appreciated - this is doing my head in!!

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem with $_SESSION

    Without seeing your code and your PHP.ini settings, it is hard to know exactly what is causing the problem. But here are a few suggestions you may want to look into:
    • Check that you are not overwriting the $_SESSION array or any of the variables in your session which you need.
    • In the PHP.ini file, look for the session.savepath setting and change this to a different directory. When you navigate to your page, the session module should create a file which matches the session ID in this directory. Open this file in a text editor such as notepad and chack that it contains the data you expect it to after each page refresh and that the file doesn't get deleted un expectedly.
    • The session module by default uses a cookie to keep track of the session ID for each user called PHPSESSID. Check that the cookie exists and check its parameters. I recommend you use Firefox for this as it gives you detailed information about the cookies, like when they expires, which domain they are valid for, which directory etc...

      Its worth noting that if the page is located on a different domain or subdomain form the other pages the session module will not be able to read the cookie it.
    • Lastly, check the cookie parameters for the session module in the PHP.ini file. All the session settings are prefixed with session.* . Make sure that these are correct.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Member
    Join Date
    Dec 2004
    Posts
    59

    Re: Problem with $_SESSION

    probably you forgot

    start_session(); on every page that needs session.

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Re: Problem with $_SESSION

    Quote Originally Posted by snappel
    Cookies are definitely enabled, $_SESSION is definitely being set, all pages have 'session_start();'

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem with $_SESSION

    Did you try what I suggested?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Re: Problem with $_SESSION

    I tried the bits I could. I can't access PHP.ini because it's locked off (not my webserver). I moved the whole site to a different subdirectory and it worked fine. Strange...

Posting Permissions

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



Click Here to Expand Forum to Full Width