Skip to content
Advertisement

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?

Advertisement

Answer

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).
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement