Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP mailing system and use of sessions

     

toplisek

3:19 pm on Jul 6, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



When there is mail PHP function and it is validated with redirection to Thank you page, I like to know how to avoid when sending contact forms. When users RELOAD page at Thank you page it will send as many emails (none content) as it is reloaded.

How to avoid this in the correct way with PHP script.

phranque

9:42 pm on Jul 6, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



if you are properly redirecting to a thank you page there shouldn't be any way for a refresh of the thank you page to resend the POST request.

swa66

5:54 pm on Jul 7, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I'll try to elaborate a bit:

The correct way:

You have a form sent to the browser in HTML - PHP script or static or... doesn't matter.

Inside the form there's an action="...." that points to a PHP script on your server.
When the user submits the form, that script will receive a GET or POST request and the script will execute on the server.

The script upon success does what it needs to do and emits a 302 redirect to the browser, pointing to another URL that shows the thank you page (can be another PHP script, static content, ... whatever).

The browser contacts the server for the thank you page.

If the user presses refresh all they do is reload the thank you page; if the user goes back they end up on the form again, which they could resubmit.

If you want to avoid that last, you have a bit of work as you now need to know to keep track of state and have the server know who already submitted what form etc. [Multiple techniques exist. But I doubt it's your problem, nor is it a problem with contact forms in general - yet].

toplisek

11:26 am on Jul 8, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



This is an issue:
If the user presses refresh all they do is reload the thank you page;

thank you page should UNset session variables and mail function should not be executed.

swa66

2:46 pm on Jul 8, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Nope.

The redirect issued by the script getting the input from the form makes sure the thank you page doesn't do any processing. SO you can leave session etc. all intact.

Just DO NOT output the thank you from the script that processes the form input. A redirect inbetween these is essential.

toplisek

1:21 pm on Jul 9, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Just DO NOT output the thank you from the script that processes the form input.

I'm new to this. How to DO NOT output the thank you.

rajivatre

1:50 pm on Jul 9, 2013 (gmt 0)

5+ Year Member



After you finish sending email from your php script just redirect the page to thankyou.htm page.

Redirection code in php is as below.
header("Location:thankyoupage.htm");

So even if user refreshes the page it will be thankyou.htm and not your php page.

Thanks
Rajiv
 

Featured Threads

Hot Threads This Week

Hot Threads This Month