Reputation: 381
The problem is that every time I refresh the page or when I change the page to another one, the session_id changes and new session file is created in session_save_path. Here is the initial part of my code:
<?php
session_start();
echo session_id();
...
?>
Obviously the session variables (which is the thing that I need) don't work.
A curious thing is that the page works fine on localhost but doesn't work when I try it on the server.
Thanks in advance.
Upvotes: 2
Views: 2306
Reputation: 12826
Check this setting in your server: session.auto_start
This will cause session to be autostarted in each page whether you call session_start()
or not.
Make sure that there are no phantom CRLFs
or such stuff before session starts. In production the error_reporting can be off so it might not get caught, but the session might find difficulty getting written. This can sometimes cause this.
Upvotes: 2
Reputation: 103
Looks like your directory with sessions is not writable.
That's why php generates a new session file each time. Check your chmod for sessions folder.
Upvotes: 0
Reputation: 685
On your server, in php.ini
check TTL for your cookies. session.cookie_lifetime
defines how long the cookie will last in seconds (default is 0, which means until the browser is closed) and session.gc_maxlifetime
defines how long before the data is deleted, also in seconds.
And make sure the session file isn't stored in a /tmp
folder.
Upvotes: 0