session_create_id Create new session id
发表日期:2021-07-01 08:56:50 | 来源: | | 浏览(908) 分类:Session 函数
session_create_id
(PHP 7 >= 7.1.0, PHP 8)
session_create_id — Create new session id
说明
$prefix
= ""): string|falsesession_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.
参数
-
prefix
-
If
prefix
is specified, new session id is prefixed byprefix
. Not all characters are allowed within the session id. Characters in the rangea-z A-Z 0-9 , (comma) and - (minus)
are allowed.
返回值
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.
范例
示例 #1 session_create_id() example with session_regenerate_id()
<?php // My session start function support timestamp managementfunction 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 functionfunction my_session_regenerate_id() { // Call session_create_id() while session is active to // make sure collision free. if (session_status() != PHP_SESSION_ACTIVE) { session_start(); } // WARNING: Never use confidential strings for prefix! $newid = session_create_id('myprefix-'); // Set deleted timestamp. Session data must not be deleted immediately for reasons. $_SESSION['deleted_time'] = time(); // Finish session session_commit(); // Make sure to accept user defined session ID // NOTE: You must enable use_strict_mode for normal operations. ini_set('session.use_strict_mode', 0); // Set new custom session ID session_id($newid); // Start with custom session ID session_start(); } // Make sure use_strict_mode is enabled.// use_strict_mode is mandatory for security reasons.ini_set('session.use_strict_mode', 1); my_session_start(); // Session ID must be regenerated when// - User logged in// - User logged out// - Certain period has passedmy_session_regenerate_id(); // Write useful codes?>
参见
- session_regenerate_id() - 使用新生成的会话 ID 更新现有会话 ID
- session_start() - 启动新会话或者重用现有会话
- session.use_strict_mode
- SessionHandler::create_sid() - Return a new session ID
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- session_abort Discard session array changes and finish session(0)
- session_cache_expire 返回当前缓存的到期时间(0)
- session_cache_limiter 读取/设置缓存限制器(0)
- session_commit session_write_close() 的别名(0)
- session_create_id Create new session id(0)
- session_decode 解码会话数据(0)
- session_destroy 销毁一个会话中的全部数据(0)
- session_encode 将当前会话数据编码为一个字符串(0)
- session_gc Perform session data garbage collection(0)
- session_get_cookie_params 获取会话 cookie 参数(0)
- session_id 获取/设置当前会话 ID(0)
- session_module_name 获取/设置会话模块名称(0)
- session_name 读取/设置会话名称(0)
- session_regenerate_id 使用新生成的会话 ID 更新现有会话 ID(0)
- session_register_shutdown 关闭会话(0)
- session_reset Re-initialize session array with original values(0)
- session_save_path 读取/设置当前会话的保存路径(0)
- session_set_cookie_params 设置会话 cookie 参数(0)
- session_set_save_handler 设置用户自定义会话存储函数(0)
- session_start 启动新会话或者重用现有会话(0)
- session_status 返回当前会话状态(0)
- session_unset 释放所有的会话变量(0)
- session_write_close Write session data and end session(0)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)