PHP5.5中未记录的会话接口是什么?
在PHP5.5.1中,有一个对SessionIdInterface的引用。但是,它仍然没有文档,我唯一能找到的是接口定义:PHP5.5中未记录的会话接口是什么?,php,sessionid,Php,Sessionid,在PHP5.5.1中,有一个对SessionIdInterface的引用。但是,它仍然没有文档,我唯一能找到的是接口定义: interface SessionIdInterface { public function create_sid (); } 依赖此接口安全吗 在哪里可以找到有关此接口的文档 根据PHP源代码: /* {{{ SessionIdInterface functions[] */ static const zend_function_entry php_sess
interface SessionIdInterface {
public function create_sid ();
}
- 依赖此接口安全吗李>
- 在哪里可以找到有关此接口的文档
/* {{{ SessionIdInterface functions[]
*/
static const zend_function_entry php_session_id_iface_functions[] = {
PHP_ABSTRACT_ME(SessionIdInterface, create_sid, arginfo_session_class_create_sid)
{ NULL, NULL, NULL }
};
/* }}} */
/* {{{ SessionHandler functions[]
*/
static const zend_function_entry php_session_class_functions[] = {
PHP_ME(SessionHandler, open, arginfo_session_class_open, ZEND_ACC_PUBLIC)
PHP_ME(SessionHandler, close, arginfo_session_class_close, ZEND_ACC_PUBLIC)
PHP_ME(SessionHandler, read, arginfo_session_class_read, ZEND_ACC_PUBLIC)
PHP_ME(SessionHandler, write, arginfo_session_class_write, ZEND_ACC_PUBLIC)
PHP_ME(SessionHandler, destroy, arginfo_session_class_destroy, ZEND_ACC_PUBLIC)
PHP_ME(SessionHandler, gc, arginfo_session_class_gc, ZEND_ACC_PUBLIC)
PHP_ME(SessionHandler, create_sid, arginfo_session_class_create_sid, ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};
SessionIdInterface
中没有任何其他方法,并且此界面中的create_sid
与SessionHandler
SessionIdInterface
是作为PHP5.5.1的一部分创建并登录到PHP5.5.1中的。其中讨论了一些细节
简而言之,您的sessionhandler接口
实现还可以实现SessionIdInterface
,并提供一个返回字符串的create_sid
方法。PHP将自动调用create_sid
,而不是使用PHP.ini中定义的内部会话创建函数
下面是一个示例脚本,演示如何使用
<?php
class SillySessionHandler implements SessionHandlerInterface, SessionIdInterface {
static $lol_sessions = [];
public function open($save_path, $filename) { return true; }
public function close() { return true; }
public function destroy($session_id) { return true; }
public function gc($lifetime) { return true; }
public function read($session_id) {
return array_key_exists($session_id, static::$lol_sessions) ? static::$lol_sessions[$session_id] : null;
}
public function write($session_id, $session_data) {
static::$lol_sessions[$session_id] = $session_data;
echo "Session data: ", $session_data;
}
public function create_sid() {
$sid = bin2hex(openssl_random_pseudo_bytes(16));
static::$lol_sessions[$sid] = [];
return $sid;
}
}
$handler = new SillySessionHandler;
session_set_save_handler($handler, true);
session_start();
echo "Your session ID is ", session_id(), "<hr>";
$_SESSION['foo'] = 'bar';
感谢您深入到源代码中,(我自己也这么做了=P),但我希望得到关于接口的更详细的解释,这就是我要寻找的信息。知道为什么文档中没有包含该接口吗?不幸的是,不知道。也许他们认为还没准备好?可能只是疏忽。