【发布时间】:2019-10-06 08:33:20
【问题描述】:
这里是html代码
<!
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>
<form action="test.php" method="POST">
<input type="text" name="pseudo">
<input type="submit">
</form>
</body>
</html>
表单返回名为 test.php 的页面中的输入值和 coockie 中的股票,但它不起作用
这里是php代码
<?php
setcookie("pseudo", $_POST['pseudo'], time() + 365*24*3600);
echo "Your name is " . $_COOKIE['pseudo'];
【问题讨论】:
-
$_COOKIE['pseudo']无法立即使用,除非您执行刷新(即您的 php 读取 cookie)或在设置 cookie 标头的同时手动设置$_COOKIE['pseudo']。