[英]How do I set the PATH in the PHPSESSID cookie?
I have many projects running on my server all of which use PHP sessions for authentication. 我的服务器上运行了很多项目,所有项目都使用PHP会话进行身份验证。
Now since the PHPSESSID cookie sets the cookie path to '/' in the set-cookie header, this cookie is available throughout the domain, whereas I need it available only to the current application. 现在,由于PHPSESSID cookie将cookie路径设置为set-cookie头中的'/',因此该cookie在整个域中都可用,而我只需要它可用于当前应用程序。
Because of this, the following problem occurs : 因此,会出现以下问题:
A user who is logged into mysite.com/application-1 automatically gets logged into 登录到mysite.com/application-1的用户会自动登录
..etc ..等等
So, How do I set the path of the PHPSESSID cookie ? 那么,如何设置PHPSESSID cookie的路径?
By default the session cookie get created with the current path until you change it to save cookie on any other path or '/'
. 默认情况下,会话cookie是使用当前路径创建的,直到您将其更改为在任何其他路径或
'/'
上保存cookie。
You may tell your script to save session cookie on the project specific directory. 您可以告诉脚本将会话cookie保存在项目特定目录中。 You can use the session_set_cookie_params for this.
您可以使用session_set_cookie_params 。 This must be called before the
session_start()
这必须在
session_start()
之前调用
session_set_cookie_params(0,'/dirname');
您只需为每个站点指定会话名称,它就会将会话彼此分开。
session_name("application-1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.