Matt Fletcher
Matt Fletcher

Reputation: 355

PHP Session ID being regenerated automatically

I have found that on my simple web application, if you leave the page alone for more than about five minutes and then reload the page, calling session_id() will return a different value the second time. Users remain logged in, so the session data is being moved across to the new ID, but I keep track of cart items in a MySQL database based on the session ID, and when the ID changes, the association with the cart items is lost.

Nowhere in my code do I ever call session_regenerate_id()

Help!

Upvotes: 2

Views: 1268

Answers (2)

Ievgen Baziak
Ievgen Baziak

Reputation: 93

Few more things you might want to check if encountered such situation AND you do use session_name():

  1. From PHP Online Manuals:

Warning! The session name can't consist of digits only, at least one letter must be present.

  1. Make sure you dont have spaces in your session_name() argument like

session_name('blah blah')

Both situations force a new session id generated every time.

Upvotes: 0

Reid Johnson
Reid Johnson

Reputation: 1394

You might want to check your code to see if you are using session_id() with an argument anywere as this will also change the session id. Without seeing the code it is hard to be specific as to a fix or to know what is going wrong.

Upvotes: 0

Related Questions