Jump to content

Reloading Thank You Page


kaliok

Recommended Posts

What is the best way (if I am not using a database) to stop the following problem:

 

I have a mail form that after performing a captcha an email is sent using php's mail and a Thank you messages is displayed. The problem is that when the page is reloaded it resends the mail.

 

Is there a way around this?

 

Thanks for any help in advance.

Link to comment
https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/
Share on other sites

Redirect the user using header?

 

Set it up so it redirects the user after the email is sent to the welcome page. The welcome page shouldn't be the one sending the email.

 

Agreed, a submit form should always use the methodology:

 

Form Page ---submits to---> Email Sending Page ---header() redirect---> Thank you page

 

That way, if they refresh, it just refreshes the Thank you page

set a variable in COOKIE or SESSION or just a GET or POST variable that is a boolean

 

set the cookie variable here w/ cookie:

$_COOKIE['mailSent'] = false

if(isset($_COOKIE['mailSent']) && $_COOKIE['mailSent'] == false) {
   //send mail and set $_COOKIE['mailSent'] to false
} else {
   //don't send mail
}
/*
you can do the same thing with session data (SESSION rather than COOKIE) but you have to start the page with session_start() and there's
more complications with using sessions (like killing them)
*/

//another method is to use GET
index.php?mailSent=false

if(isset($_GET['mailSent']) && $_GET[] == true
//same logic as the COOKIE example

 

 

The redirect idea above is the best solution IMO, however.

For the welcome page, put a redirect on that too, but not with PHP. Use a <meta> redirect and count off in 5 secs so it will redirect the user to whatever page in 5 seconds. Put a note like: You will be redirected in 5 seconds and a link below that like (Click here if you don't want to wait)

 

That would help so the user wouldn't press the back button. Not saying he or she can't, but this helps move things forward and not back.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.