shuman

[php-cookie] cookie 请求跨域,如何共享

 cookie 请求跨域的问题, 假设我有两个域名,一个 m.example.com,另一个是 www.example.com 。

那么我需要如何设置 cookie 才可以在这两个域名都实现共享呢?

 

// m.example.com & www.example.com 的根域名都是 example.com
// 所以在 setcookie 时,我们只需要在指定的 $domain 设置为了该公共的根域名即可,实现两个域名共享访问 cookie 值

// bool setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] )

 setcookie(\'cookie_4000\', json_encode($_REQUEST), time()+86400 , \'/\'  , \'.example.com\');

 

分类:

技术点:

相关文章:

  • 2021-10-19
  • 2021-10-19
  • 2021-12-06
  • 2022-12-23
  • 2021-10-19
猜你喜欢
  • 2021-12-16
  • 2021-12-16
  • 2021-10-19
  • 2021-10-19
  • 2021-10-19
相关资源
相似解决方案