0

我有一台服务器,但有两个目录,例如:

  • 万维网
    • 目录1
      • 索引.php
      • page1.php
      • page2.php
    • 目录2
      • 索引.php
      • page3.php
      • page4.php

当我想从 的页面转移到 的页面index.php时,如何传递使用 PHP页面中设置的 cookie?Directory1index.phpDirectory2index.phpDirectory1

4

3 回答 3

1

使用path参数:

setcookie("name", "value", time() + 3600, "/");
于 2012-07-25T15:21:53.417 回答
1

根据 PHP 文档

cookie 可用的服务器上的路径。如果设置为“/”,cookie 将在整个域中可用。如果设置为 '/foo/',则 cookie 将仅在 /foo/ 目录和域的 /foo/bar/ 等所有子目录中可用。默认值是设置 cookie 的当前目录。

$time = time() + 3600;
setcookie('foo', 'bar', $time, "/");

当您设置第四个参数即pathas/时,您可以在域级别访问它,我想这就是您所需要的。

于 2012-07-25T15:22:58.073 回答
0

只是不要设置可选的 Path 参数,然后它对两个目录都可用。

于 2012-07-25T15:23:08.907 回答