Home > Backend Development > PHP Tutorial > 请问一个网站互不关联的不同页面如何获取同一cookie值?

请问一个网站互不关联的不同页面如何获取同一cookie值?

WBOY
Release: 2016-06-23 13:07:35
Original
1417 people have browsed it

比如说一个网站同一个目录下有几个互不关联的页面:1.php,2.php,3.php
一个用户访问1.php后生成cookie:

 
 setcookie('mycookie1',$c1);
 setcookie('mycookie2',$c2);
 setcookie('mycookie3',$c3);



如果这个用户从别的网站点击超链接进入2.php,结果在2.php中不能读到1.php设置的cookie值。
如果我在1.php中做个超链接连到3.php,从1.php点超链接访问3.php,在3.php上就能显示出我在1.php设置的cookie值:
2.php和3.php的代码都一样:

$cc1 = $_COOKIE['mycookie1'];
$cc2 = $_COOKIE['mycookie2'];
$cc3 = $_COOKIE['mycookie3'];
echo $cc1;
echo $cc2;
echo $cc3;



请问怎样才能在跟1.php完全关联的3.php页面中读取到1.php设置的cookie值?


回复讨论(解决方案)

设置 cookie 变量的失效期

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template