Moon
Moon

Reputation: 22605

Different session ID every time session_start is executed

I have the following source code

session1.php

<?php

session_start();
echo session_id();

?>

session2.php

<?php

session_start();
echo session_id();

?>

when I access session1.php then access session2.php, I get a different ouput.

Why is this doing it?

Upvotes: 2

Views: 4247

Answers (4)

kmoser
kmoser

Reputation: 9308

If you're running under *nix, try setting session.save_path to /tmp. If that doesn't work, look in your browser's cookie cache to see if the cookie is indeed being saved by the browser.

Upvotes: 0

SharpC
SharpC

Reputation: 7464

A rare edge case, but I found that having a dot in the session name of php.ini caused this problem!!

session.name = THIS.DOESNTWORK

Upvotes: 0

Brian
Brian

Reputation: 1

Try storing your session cookies in the database rather than on the server. This saved me heaps of time out and other session cookie problems especially if you are on a shared server.

This might help: http://www.raditha.com/php/session.php.

Good Luck

Upvotes: 0

Oswald
Oswald

Reputation: 31685

The browser is not sending the session cookie back to the server. This can have two reasons.

  1. The browser is configured not to send cookies to the server. You cannot force the browser to send cookies. In this case your only option is to pass the session identifier in the URL, although this is generally not a good idea.
  2. The server is configured not to use cookies for the session identifier (by means of the session.use_cookies configuration option).

Upvotes: 3

Related Questions