PHP cookie problem - www or without www

后端 未结 4 1017
温柔的废话
温柔的废话 2020-11-29 10:02

Why is it that if I create a cookie on www.example.com and check it on example.com, the cookie doesn\'t exist there? I am planning to just use .htaccess redirec

4条回答
  •  死守一世寂寞
    2020-11-29 10:51

    I believe you can set the cookie at example.com (really .example.com) and it will be sent if they go to www.example.com, but not vice versa. This standard security policy is to prevent users' private data from being sent to unintended servers.

    Personally, I use virtualhosts in my apache2.conf:

    
        ServerName example.com
        RedirectMatch (.*) http://www.example.com$1
    
    

    ... in this example, everyone trying to load e.g. http://example.com/index.html is redirected to http://www.example.com/index.html.

提交回复
热议问题