session_create_id

(PHP 7 >= 7.1.0, PHP 8)

session_create_idCreate new session id

Description

session_create_id(string$prefix = ""): string|false

session_create_id() is used to create new session id for the current session. It returns collision free session id.

If session is not active, collision check is omitted.

Session ID is created according to php.ini settings.

It is important to use the same user ID of your web server for GC task script. Otherwise, you may have permission problems especially with files save handler.

Parameters

prefix

If prefix is specified, new session id is prefixed by prefix. Not all characters are allowed within the session id. Characters in the range a-z A-Z 0-9 , (comma) and - (minus) are allowed.

Return Values

session_create_id() returns new collision free session id for the current session. If it is used without active session, it omits collision check. On failure, false is returned.

Examples

Example #1 session_create_id() example with session_regenerate_id()

<?php
// My session start function support timestamp management
function my_session_start() {
session_start();
// Do not allow to use too old session ID
if (!empty($_SESSION['deleted_time']) && $_SESSION['deleted_time'] < time() - 180) {
session_destroy();
session_start();
}
}

// My session regenerate id function
function my_session_regenerate_id() {
// Call session_create_id() while session is active to

See Also

To Top