![]() |
Email script problem
I have had a script running that once a user enters their information it will email it to me. However, if they hit refresh it sends it again. How would I go about preventing this from happening?
Thanks for any help. |
Quote:
|
Its just the basic mailto function.
Code:
$to = "email@address.com"; |
Quote:
If you include an IF conditional that will check for a specific status, it will only run once.. I like to base it off a hidden POST variable say, "submit_form" and set that value to true. Then on the receiving page, make sure that it is set to true, then run your mail function. After your mail function, unset that variable, that way it won't be true anymore and then if they hit refresh, it won't send the email. |
Thanks for your response. I'm not very familiar with PHP yet, so can show me some example code or a site so I can reference from? I need to see it to figure it out and inderstand it.
Thanks |
PHP/ELSE
PHP/EXIT PHP/MAIL PHP/IF this should be a good start. PS: the best way to go is to read all of php.net manual one or two times.. PHP Manual |
Have the page that actually sends the page redirect, the HTML code for this is (put this in the <head>):
Code:
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD> |
The
header function will also redirect using GET and therefore prevent any reloading.php Code:
|
Now to make things more complicated :-P
You could also take the IP of the user, log it, and check whether he already send you a message in - lets say last hour. If yes, then he's not allowed to send more messages. Using this way you could also make sure that your Mailbox does not get spammed from one user. -> There are many people out there who just love writting such little programms. |
I think I should have explained the whole thing. This site is an incident reporting site.
Page 1:
Page 2:
|
Quote:
You could do this a couple of ways: 1. the most simple method -> redirect the user to another page after he/she has submitted the form (after you send the e-mail) 2. use a 'security key' (this is what I call it). What does this mean? Each time you show the user the page, you also generate a hash key (an md5 of variable data), which you will store in the session. Then, when the user hits the submit button and after you validate your form, etc., you check that session variable against what you would expect. If it's different, you can reset the form values and present the user with a message saying "please use the submit button" or such. Something like this: Code:
if(form_submitted)So, the best choice would be #2. |
I'll provide some simple code later today to help you on your way...
|
Quote:
Hmm true - didn't think of that. Considering that I would also choose the Session - Solution. :-D |
| All times are GMT. The time now is 04:19 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0