[英]Is it possible to assign session_id() a value in php?
Is it possible to assign session_id() a new value manually? 是否可以手动分配session_id()新值?
I've tried the following but it's not working: 我已经尝试了以下方法,但是没有用:
session_start();
$sessionId = session_id();
echo $sessionId;
if ($sessionId != $ses) {
session_id() = $ses;
}
You can using session_id()
: 您可以使用
session_id()
:
session_id($sessionId);
session_id()
can be used to either get the session ID or set it by passing in an optional function argument as I have done above. session_id()
可以用来获取会话ID或通过传递可选的函数参数来进行设置(如我在上文所述)。
It is worth noting the following from the manual with regard function call order and session ID character restrictions: 值得注意的是,手册中有关函数调用顺序和会话ID字符限制的以下内容:
If id is specified, it will replace the current session id.
如果指定了id,它将替换当前的会话ID。 session_id() needs to be called before session_start() for that purpose.
为此,需要在session_start()之前调用session_id()。 Depending on the session handler, not all characters are allowed within the session id.
根据会话处理程序的不同,会话ID内不允许所有字符。 For example, the file session handler only allows characters in the range az AZ 0-9 , (comma) and - (minus)!
例如,文件会话处理程序仅允许az AZ 0-9范围内的字符,(逗号)和-(减号)!
You have to assign the id BEFORE you start the session. 开始会话之前,您必须分配ID。
session_id('hello');
start_session();
However, be careful doing this. 但是,请小心执行此操作。 The session ID is (generally) a long random alphanumeric string.
会话ID(通常)是一个长的随机字母数字字符串。 if you set it to something constant/simple, you've made it much much easier for someone to hijack your users' sessions.
如果将其设置为恒定/简单的值,则可以使他人更容易劫持用户的会话。
And if two or more people get the same session ID, they'll be SHARING the same session, since this ID is the unique identifier for a particular session. 而且,如果两个或多个人获得相同的会话ID,则他们将共享同一会话,因为此ID是特定会话的唯一标识符。 It should be unique for every user, with no duplicates.
对于每个用户,它应该是唯一的,没有重复。
是的,按照手册,您只需提供一个字符串作为session_id([string $id])
的参数即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.