homepage Welcome to WebmasterWorld Guest from 174.129.163.183
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP mailing system and use of sessions
toplisek




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

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




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

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




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

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




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

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




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

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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved