-1

我想在页面加载时读取 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 中的复选框值吗?

4

1 回答 1

1

您必须在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!)。

于 2012-05-28T08:57:32.797 回答