0

Here is a simple page I have:

<?php
session_start();

if(!isset($_SESSION['test'])) {
    $_SESSION['test'] = time();
} else {
    session_regenerate_id(true);
}

print_r($_SESSION);
?>

So it checks if session exists. If it does not exist, then it will set a value. In this example, it is time() so we can see if it has changed or not.

If the session is set, we call session_regenerate_id(true) but. It should keep showing the same time() since we have already set it in the first place, but it keeps showing different times on each refresh. I've tried removing the "true" in the regenerate function but it still does not work.

Anyone can help?

Timmy Balk
  • 238
  • 3
  • 14
  • @RaymondNijland but the session info should still transfer over to the new session, right? – Timmy Balk Aug 08 '19 at 20:36
  • it should but also read what the PHP devs warn about `session_regenerate_id()` usage on unstabile internet connections.. Example #2 code is better then using `session_regenerate_id()` keep it mind it is more or less pseudo code. – Raymond Nijland Aug 08 '19 at 20:45
  • @RaymondNijland I've tried it on multiple internet networks already. It works for my other site but not on this new one – Timmy Balk Aug 08 '19 at 20:46
  • *"It works for my other site but not on this new one "* different PHP versions? Also try [session_write_close()](https://www.php.net/manual/en/function.session-write-close.php) – Raymond Nijland Aug 08 '19 at 20:46
  • @RaymondNijland Both are PHP 7.2. I tried `session_write_close();` and it did not work – Timmy Balk Aug 08 '19 at 20:55
  • @RaymondNijland In this answer it states that the session data should not be destroyed https://stackoverflow.com/a/46947572/4357238 – Timmy Balk Aug 08 '19 at 20:57
  • *"In this answer it states that the session data should not be destroyed "* i said it should right? Annyhow let PHP run in debugging mode -> `ini_set('display_errors,' 1); error_reporting(E_ALL);` if this does not show annything.. I don't know why this random feature is happening on one server with the same PHP version.. As It does not have PHP version depening code unless the session configuration is different offcource. – Raymond Nijland Aug 08 '19 at 21:00
  • @RaymondNijland No errors at all – Timmy Balk Aug 08 '19 at 21:14

0 Answers0