简体   繁体   English

php session 变量不在页面之间保留

[英]php session variables not persisting between pages

I have a web form that was emailing itself multiple times if someone clicked the submit button more than once.我有一个 web 表单,如果有人多次单击提交按钮,它会多次发送电子邮件给自己。

In the form, I added:在表格中,我补充说:

$_SESSION["EmailSent"] = 0;

On the processing page I added:在我添加的处理页面上:

if ($_SESSION["EmailSent"] == 0){
    $_SESSION["EmailSent"] = 1;
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } 
    else {
        //echo 'Message has been sent';
    }
}

On the processing page, I'm getting the error: PHP Notice: Undefined index: EmailSent在处理页面上,我收到错误:PHP 注意:未定义索引:EmailSent

I added session_start( ) to the top of the pages.我在页面顶部添加了 session_start()。 The weird thing is that the email is still being sent and not stopped when the page encounters the error.奇怪的是,当页面遇到错误时,email 仍在发送并且没有停止。

The error was because of the thing between the seat and Keyboard.错误是因为座位和键盘之间的东西。 Me.我。

I added session_start( ) to the top of each page through a Dreamweaver template.我通过 Dreamweaver 模板将 session_start( ) 添加到每个页面的顶部。 The problem is that the processing page is not tied to the template and didn't have the code.问题是处理页面没有绑定到模板并且没有代码。 I added it to the page and it's working.我将它添加到页面并且它正在工作。 the form now submits only once.表单现在只提交一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM