3

Doc says

session_create_id() is used to create new session id for the current session. session_regenerate_id() Update the current session id with a newly generated one.

Is there any difference between these two functions ?

nithinTa
  • 1,632
  • 2
  • 16
  • 32
  • you can already read it.. `create` and `update`, but accurately `session_regenerate_id()` will replace the current session id with a new one, and keep the current session information. – Shadow Fiend Oct 26 '17 at 06:40
  • "new id" for current session & update with "new id" does it look same ? – nithinTa Oct 26 '17 at 06:41
  • Check this out https://stackoverflow.com/questions/22965067/when-and-why-i-should-use-session-regenerate-id – Abhilash Nayak Oct 26 '17 at 06:42
  • figured out that by default session_regenerate_id() = session_id ( session_create_id() ) right ? – nithinTa Oct 26 '17 at 07:06

2 Answers2

3

Yes there is a difference, session_create_id() will create a new sessionId discarding the current $_SESSION information, where as session_regenerate_id() doesn't destroys them, instead it just updates the sessionId

Referred from : http://php.net/manual/en/function.session-create-id.php & http://php.net/manual/en/function.session-regenerate-id.php

Abhilash Nayak
  • 664
  • 4
  • 10
1

session_create_id

Create new session id

session_regenerate_id

Update the current session id with a newly generated one

Usage example from the manual:

$old_sessionid = session_id();

// Set destroyed timestamp
$_SESSION['destroyed'] = time(); // Since PHP 7.0.0 and up, session_regenerate_id() saves old session data

// Simply calling session_regenerate_id() may result in lost session, etc.
// See next example.
session_regenerate_id();

// New session does not need destroyed timestamp
unset($_SESSION['destroyed']);

$new_sessionid = session_id();

echo "Old Session: $old_sessionid<br />";
echo "New Session: $new_sessionid<br />";

print_r($_SESSION);

Which leads us to the following question - why and when you should use it, there's a detailed answer in this link.

Ofir Baruch
  • 10,323
  • 2
  • 26
  • 39