Session cookie and www

前端 未结 5 975
南方客
南方客 2021-01-25 18:04

I would like to have my session work in my website when using www. AND when not using it. I\'ve read this thread: PHP cookie problem - www or without www

And this would

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 18:38

    You can reflect php.ini for this. Add this in php.ini so that your session cookie will be saved at the place to be accessible with or without www

    session.cookie_domain = .example.com 
    

    You can also try an alternate to do this

    ini_set("session.cookie_domain", ".example.com"); 
    

    And you can get the host name using $_SERVER['HTTP_HOST'] variable.

提交回复
热议问题