为什么我的cookie没有显示在链接页面上? [英] Why my cookie not showing up on linked page?

查看:73
本文介绍了为什么我的cookie没有显示在链接页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常简单的问题.

这是我的index.php:

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>

这是我的newpage.php:

this is my newpage.php:

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

我的第二页回显"ok ok",但没有回显cookie.我检查了网络,index.php的cookie是"testcookie",但是如果我单击链接,newpage.php将无法访问它.

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.

我正在使用MAMP.

推荐答案

86400 很久很久以前.

您的Cookie会立即过期.

Your cookie expires immediately.

请参见文档:

cookie过期的时间.这是Unix时间戳,以秒为单位,以秒为单位.换句话说,您很可能会使用time()函数加上希望它过期之前的秒数来进行设置.或者您可以使用mktime().time()+ 60 * 60 * 24 * 30将cookie设置为在30天后过期.如果设置为0或省略,则cookie将在会话结束时(浏览器关闭时)失效.

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).

这篇关于为什么我的cookie没有显示在链接页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆