【问题标题】:Allow one form submission cookie允许一个表单提交 cookie
【发布时间】:2013-02-28 00:28:01
【问题描述】:

我有一个表单,但我希望每个用户只发送一次,所以我想设置一个 cookie 来做到这一点。如何更改我的脚本?

我的 PHP 脚本:

<?php
if (isset($_COOKIE["Form"]) == 1)
{
//Hide form
exit();
}
if ( $_GET['value'] <> "")
{   
$adress = 'Receiver@mysite.com';
$subject = 'SUBJECT';
$text = 'TEXT';
mail($adress,
$subject,   
$text,
'From: someone@mail.here');
  $handle = fopen ( "some-doc.txt", "a" );

  fwrite ( $handle, $_GET['value'] );

fclose ( $handle );


echo "Thanks";
setcookie("Form", 1, time()+3600*24*60); // Line 108
exit;
}
?>

错误信息

Warning: Cannot modify header information - headers already sent by (output started at
form.php:6) in 
form.php on line 108

我改变了它,但现在我得到了这个错误。

【问题讨论】:

    标签: php forms cookies submission


    【解决方案1】:

    我看到你做到了:

    setcookie("Schule", 1, time()+3600*24*60);
    

    然后使用类似的方法:

    setcookie("Form", 'yes', time()+3600*24*60);
    

    现在:

    if (isset($_COOKIE["Form"]) && $_COOKIE["Form"] == 'yes')
    {
    //Hide form
    exit();
    }
    

    【讨论】:

    • 我更改了它,但现在我收到了错误消息,我在上面发布了。
    【解决方案2】:

    setcookie("Schule", 1, time()+3600*24*60); 行放在exit 语句之前,并将“Schule”替换为“Form”。

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多