【发布时间】:2017-05-19 15:23:51
【问题描述】:
我的 php 脚本有问题。我想将我的 cookie 的值打印为我创建的表单中的“值”。但它不打印它,我的网站看起来不像我想要的。这是我的代码。我得到的错误是: 注意:未定义索引:第 4 行 C:\xampp\htdocs\OpenClassroom\index.php 中的伪
提前致谢。
<?php
if (isset($_COOKIE['username']))
{
setcookie('username', htmlspecialchars($_POST['pseudo']), time() + 31536000, null, null, false, true);
}
else
{
setcookie('username', 'NewUsername', time() + 365*24*3600, null, null, false, true);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Mini-chat</title>
</head>
<style>
form
{
text-align:center;
}
</style>
<body>
<!--Form-->
<form action="commentaires.php" method="post">
<p>
<label for="pseudo">Pseudo</label> : <input type="text" value="<?php echo $_COOKIE['username'] ; ?>" name="pseudo" id="pseudo" /><br />
<label for="message">Message</label> : <input type="text" name="message" id="message" /><br />
<input type="submit" value="Envoyer" />
</p>
</form>
【问题讨论】:
-
启用
error_reporting(E_ALL);后会出现哪些错误。 cookie 设置好了吗?在你的浏览器中检查这个 -
我有这个错误:注意:未定义的索引:第 4 行 C:\xampp\htdocs\OpenClassroom\index.php 中的伪