Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

weird php session problem .... totally stumped

Options
  • 14-01-2006 11:31pm
    #1
    Registered Users Posts: 673 ✭✭✭


    Hey,

    Ok, this is freaking me out. I have been setting up a site on my testing server and it all runs fine. I have now loaded it up onto my hosting account.

    When someone logs in with their username and password the current user is saved in the current session i.e. their name and so on. Once they have logged in their name is displayed on the screen.

    For some reason when the user clicks onto a new page the name that is displayed has changed to a different user (the user it changes to first is always the same one) then when you click on another link the name changes again (the second time it changes it always changes to the same user also). Then whenever i click on any further links the name stays at the new displayed name.

    This doesnt happen on the testing server with exactly the same scripts!!

    Anyone got an idea why this could be happening?

    Thanks


Comments

  • Registered Users Posts: 849 ✭✭✭Cr8or


    Sounds like the page is cached in your broswer this often happens with php pages using sessions .. My guess is that you loged in as user X before and when you log in as user Y user X is still displayed. If this is the problem you can force the page to use nocache with headers ect.

    Try this on each session page. Dont ask where to put it or ask why your getting errors.. RTFM.

    [PHP]<?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?> [/PHP]

    If not, it may be a problem with your sessions ie you do not kill sessions or the vars inside the session are not getting reset.


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    Mmm, I'd favour the "not killing sessions properly" option.


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Well this is the first time ive used sessions on a site (Im only a learner!!) but it just doesnt make sense to me that it doesnt do this on my testing server with the exact same code and database.


  • Registered Users Posts: 673 ✭✭✭Bananna man


    CuLT wrote:
    Mmm, I'd favour the "not killing sessions properly" option.

    Im not sure if it has anything to do with not killing old sessions properly. When i login first the the correct first name and second name appear (they are stored in the session as two seperate variables) then when i click a link it changes to the same user every time no matter what user i logged in with first off. Then when i click another link the first name goes back to the first name that should be logged in but the second name chages to another variable (the variable that it changes to is always the same no matter who you logged in as first). From this point on the name doesnt change again when you click on other links.

    Just a reminder, this doesnt happen on the testing server, which makes no sense to me!!!


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Just did a bit more investigating and it turns out that the $_SESSION doesnt change even though it is dealt with exactly the same as the $_SESSION and $_SESSION. This means i can do a work around and instead of calling on the session variables for the names i can just query the database where the $_SESSION = user_id but i would like to know why this is happening for future work i am doing.

    How could it be possible that the $_SESSION doesnt change and the others do and that this doesnt happen at all on my testing server????? :confused:


  • Advertisement
Advertisement