Session_start () creates a new session with every update

I have a problem with session_start() . It creates a new session every time the page is refreshed / loaded.

here is the code:

 <?php $bob = session_id(); echo "Session ID on load is ".$bob; echo "<br>"; if($bob==""){ session_start(); $bob = session_id(); echo ' session ID currently is '.$bob; } // a bunch more stuff 

When I load the page, I get the following:

Session identifier when loading the current session identifier ed320bc5e24c871c9db8ea30e6796c14 (or option)

if I refresh the page I get:

Session identifier when loading the current session identifier fbd69d01d511a7be382799dca7279a86 (or variant)

the session id is always empty before session_start() is called, and it is always the new session_id()

It does this in all browsers, and I checked to make sure cookies are enabled.

The session save path is specified as /tmp . I don’t know exactly where it is, but looking at my root and all the other directories, I can’t find the session file (assuming that it will look something like sess_fbd69d01d511a7be382799dca7279a86).

So, I think something is happening with the save loop, but I'm too new to this to know for sure, and server administrators are pretty useless. What should be my next steps in diagnosing the problem? The server is running 5.3.22.

phpinfo here

Thanks for any help.

ps you can visit pcm.pcmxa.com to see the problem yourself if you want.

+4
source share
1 answer

If your session directory (most similar to / tmp , as you said) is not writable, it will not be able to save and will have to update a new one each time. Here is how you can verify this:

 if ( !is_writable(session_save_path()) ) { echo 'Session save path "'.session_save_path().'" is not writable!'; } 

If this is the case, you need the server administrators to display what your web server has ever run as permission to write to the / tmp directory.

+4
source

All Articles