当我向动作处理脚本提交表单时,我应该设置cookie。但饼干还没准备好。
<input type="email" name="fes-email" class="fes-input" value="<?php echo $_COOKIE['hotspot-user-email']; ?>" placeholder="Еmail">这可以在处理脚本页面上找到。
setcookie('hotspot-user-email', $_POST['fes-email'], time() + (86400 * 30), 'domain.tld'); 我尝试的是将电子邮件地址保存在cookie中,以便下次用户返回地址时将在输入字段中回显。
我的代码有问题吗?
if(!empty($_POST['fes-email'])) {
if (filter_var($_POST['fes-email'], FILTER_VALIDATE_EMAIL)) {
setcookie('hotspot-user-email', $_POST['fes-email'], time() + (86400 * 30), '/'); // 86400 = 1 day
}else { echo("EMAIL IS NOT VALID"); }
}else { echo("EMPTY FIELD"); }发布于 2015-02-01 14:31:36
下面是执行魔术的最简单的片段
<?php
if (isset($_COOKIE['testCookie'])) {
echo "<br/> Cookie is set: " . $_COOKIE['testCookie'] ." <br/>";
} else {
if (setcookie('testCookie','myemail@mydomain.com', time() + 86400)) {
echo "<br/> cookie is set <br/>";
}
}
?>发布于 2015-02-01 13:51:57
你只为"domain.tld“设置了cookie
请测试此地址的所有页面的代码:
setcookie('hotspot-user-email', $_POST['fes-email'], time() + (86400 * 30), '/'); https://stackoverflow.com/questions/28263380
复制相似问题