Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为两个域设置cookie_Php_Session_Cookies_Session Cookies_Zen Cart - Fatal编程技术网

Php 为两个域设置cookie

Php 为两个域设置cookie,php,session,cookies,session-cookies,zen-cart,Php,Session,Cookies,Session Cookies,Zen Cart,我正在尝试为同一站点设置两个cookie。(一个是HTTP,一个是HTTPS站点除外。) 假设HTTP_服务器包含和HTTPS_服务器包含,我将使用以下内容 setcookie("referrer_key", $_GET['referrer'], time() + 60*60*24*365, $cookie_domain_http['path'], $cookie_domain_http['host']); // Set the cookie fo

我正在尝试为同一站点设置两个cookie。(一个是HTTP,一个是HTTPS站点除外。)

假设HTTP_服务器包含和HTTPS_服务器包含,我将使用以下内容

   setcookie("referrer_key",
     $_GET['referrer'],
     time() + 60*60*24*365,
     $cookie_domain_http['path'], 
     $cookie_domain_http['host']); // Set the cookie for the non-HTTPS version.

if(ENABLE_SSL == "true") {
   setcookie("referrer_key",
     $_GET['referrer'], 
     time() + 60*60*24*365, 
     $cookie_domain_https['path'], 
     $cookie_domain_https['host']); // Set the cookie for HTTPs version.
}
现在,第一个
setcookie
正在正确设置会话cookie。但是,第二行并没有使其显示

如何使用这段代码,特别是PHP来实现这一点。

最后还有一个参数,可以用来指定cookie是否安全

if (ENABLE_SSL == "true") 
  setcookie("referrer_key", 
  $_GET['referrer'], 
  time() + 60*60*24*365, 
  $cookie_domain_https['path'], 
  '.somesite.com', // Parse out the base domain, and put it here with the leading "."
  true); //this is the parameter to set specify a secure cookie

最后还有一个参数,可以用来指定cookie是否安全

if (ENABLE_SSL == "true") 
  setcookie("referrer_key", 
  $_GET['referrer'], 
  time() + 60*60*24*365, 
  $cookie_domain_https['path'], 
  '.somesite.com', // Parse out the base domain, and put it here with the leading "."
  true); //this is the parameter to set specify a secure cookie

您只能在一个域中设置cookie,即运行代码的域。您可以获得的最接近的设置是somesite.com,在这种情况下,它将被发送到somesite.com的所有子域

不能在同一段代码中同时在somesite.com和othersite.com上设置cookie


否则,没有任何东西可以阻止您为任意域添加cookie。

您只能在一个域中设置cookie,即您的代码正在运行的域。您可以获得的最接近的设置是somesite.com,在这种情况下,它将被发送到somesite.com的所有子域

不能在同一段代码中同时在somesite.com和othersite.com上设置cookie


否则,没有什么可以阻止您为任意域添加Cookie。

当我这样做时,它不会添加到我的Cookie列表中。也许更好的答案是使用.somesite.com方法。请稍后查看新答案。不过,当我这样做时,它不会添加到我的cookies列表中。也许更好的答案是使用.somesite.com方法。请稍后查看新答案