Corfitz.
Corfitz.

Reputation: 1884

PHP session resets somehow

I am working on a website where it is possible for the current user to choose different cities to look in.. I don't want to keep the city in the URL and I don't want to depend on a cookie, if the client will not accept cookies.. I am doing it in sessions then, but somehow the session stops very early and I don't understand what is wrong..

if (isset($_GET['c'])) {
unset($_SESSION['city']); 
$_SESSION['city'] = $_GET['c'];
}
if (empty($_SESSION['city'])) {
$_SESSION['city']='07400';
}
$city = $_SESSION['city'];

after I click three pages around, the the city is back to 07400.. In some way.. the Session gets empty.. but I don't know how...

Upvotes: 0

Views: 259

Answers (2)

Corfitz.
Corfitz.

Reputation: 1884

After working on the script long enough, I found out, that nothing was wrong with the city script... Nothing was wrong with the Sessions.. But because of a scripting mistake later in the script, it destroyed the $_SESSION['city'].. Thanks for all the replies.. And thanks for the tips to look for mistakes, and maybe a changed session id...

Upvotes: 0

martinstoeckli
martinstoeckli

Reputation: 24081

Without the possibility to test/debug your project, it is very difficult to find out the problem. Nevertheless this could help getting you on the right track:

I would give out the session-id on every page you are requesting like that: print(session_id());.

If the session-id changes, you have lost your session and should check how the id is passed and the session is recreated (cookie, id in url, session_start). I would also write the code error_reporting(E_ALL); at the begin of the pages, to see if you get a header-already-sent warning.

If the session-id remains constant, the session is recreated correctly. Then i would search the project for code, that writes to the session and possibly resets the variable.

Upvotes: 1

Related Questions