【问题标题】:How to write session for both www. and non-www version of my domain?如何为两个 www 编写会话。和我的域的非 www 版本?
【发布时间】:2011-11-26 19:30:23
【问题描述】:

我正在mydomain.com/login.php 上写会话我相信这在www.mydomain.com 中无法访问。那正确吗?

如何写入 $_SESSION 以便我可以从 www.我的域的非 www 版本?

【问题讨论】:

  • 从 www 到非 www 或从非 www 到 www 进行永久 301 重定向。它也有 SEO 的好处(?)

标签: php session


【解决方案1】:

看看session_set_cookie_params 它解释了在域中设置. 也将允许访问子域,

Cookie domain, for example 'www.php.net'. To make cookies visible on all 
subdomains then the domain must be prefixed with a dot like '.php.net'.

三木有一个例子

http://www.php.net/manual/en/function.session-set-cookie-params.php#94961

【讨论】:

  • 在测试此更改之前清除所有设置的 cookie 非常重要..
【解决方案2】:

session_set_cookie_params("$lifetime","$path","$domain","$secure","$httponly") 是 php 语言中最好的一种,用于在两个 www 中设置会话和非www url

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2012-10-17
    • 2017-12-04
    • 2014-03-04
    • 1970-01-01
    • 2018-01-07
    • 2011-04-02
    相关资源
    最近更新 更多