kaliok Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/ Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-433868 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 You could use a session to check it Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-433871 Share on other sites More sharing options...
rhodesa Posted January 8, 2008 Share Posted January 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-433879 Share on other sites More sharing options...
nikefido Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-433880 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 I find it rather useless to set a session/cookie just for this. Just more work and more complications. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-433885 Share on other sites More sharing options...
nikefido Posted January 8, 2008 Share Posted January 8, 2008 indubitably Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-433890 Share on other sites More sharing options...
kaliok Posted January 8, 2008 Author Share Posted January 8, 2008 Thanks guys. I think the best way to do it looks like the redirect, that way the user is can refresh to his hearts content and it won't make any difference. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-434026 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 They'll just hit Back instead. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-434029 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85075-reloading-thank-you-page/#findComment-434034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.