我现在正在学习 PHP。任何人都可以看看这个,看看为什么 cookie 没有设置并一直显示为空?
<?php
if ($_COOKIE["name"]) {
echo "welcome back" . $_COOKIE['name'];
}
else {
$fname = $_POST["fname"];
$age = $_POST["age"];
if ($fname) {
echo "your name is ".$fname;
setcookie("name", $fname, time()+6000);
echo "cookie" . $_COOKIE['name'];
}
if ($age) {
echo "your age is " . $age;
}
}
?>
<html>
<body>
<form action="index.php" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">
</form>
<a href="info.php">info</a>
</body>
</html>