简体   繁体   中英

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.

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

I added session_start( ) to the top of the pages. The weird thing is that the email is still being sent and not stopped when the page encounters the error.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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