PHP会话问题:在网站上同时进行两次同一会话

Just experienced a weird thing. Using same browser, operating system and loading same website in two different computers results in the same session - so when the computer A is adding to cart, computer B can refresh the page and see the item added in cart.

What is causing this and how can this be prevented? Is this on a higher layer than PHP? Maybe a server configuration?

The website is using PHP sessions.

PHP session ID is not unique have collisions on high traffic websites.

To overcome this you can keep track of session ID's:

  1. Generate a random number using PHP and hash it with md5. Insert that number into the table and that is the new session ID.
  2. When generating a number, verify it's unique with a database query. If not, start the process over again.
  3. Automatically archive session IDs after 24 hours to keep the table as small as possible.

Read more