doucheng9058 2017-10-26 13:30
浏览 185
已采纳

为什么我的cookie没有显示在链接页面上?

very simple question.

This is my index.php:

<?php
setcookie("testcookie", "i am value of cookie", 86400, '/');

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>

<a href="newpage.php">go to next</a>
</body>
</html>

this is my newpage.php:

<?php
echo "ok ok ";
echo $_COOKIE["testcookie"];
?>

My second page echoes "ok ok " but it doesn't echo the cookie. I checked network, the index.php has the cookie "testcookie" but newpage.php doesn't have access to it if I click the link.

I'm using MAMP.

  • 写回答

1条回答 默认 最新

  • dpdkqls6399 2017-10-26 13:35
    关注

    86400 is a long, long time ago in the past.

    Your cookie expires immediately.

    See the documentation:

    The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器