我想在页面加载时读取cookie,并希望能够在用户按下表单上的提交按钮时保存它们。
由于服务器端脚本在 html 加载之前运行,我不知道如何将用户信息从表单发送到setcookie()
例如:
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
<div><input name="login" type="text" class="textfield" id="login" /></div>
<div><input name="password" type="password" class="textfield" id="password" /></div>
<div><input type="checkbox" name="checkbox" value="true" id="checkbox" /> Remember me</td></div>
</form>
然后,这是用于设置 cookie 的功能:
setcookie(name, value, expire, path, domain);
选中复选框时,如何将表单中的信息放入$value
变量中?我需要在 html 或 php 中选中复选框值吗?
您必须
在login-exec.php中使用包含表单数据的$_POST变量执行此操作:
<?php
if (isset($_POST['checkbox'])) {
// guessing how to retrieve the other fields is left as an exercise
// setcookie('name', 'value');
}
?>
但是,正如其他人所说,您真的应该阅读一些有关如何制作安全记住我系统的文章(或询问SO!