Page 1 of 1

avoid duplicated mails on browser refresh

Posted: Mon Aug 02, 2010 12:06 pm
by atomiccx
Hello, guys. I'm using the following code to send me an automated mail in case the user find a broken link. But there are 2 problems: 1) after submitting I'd rather not disrupt their game by refreshing the page. So, is there any way to send mail without the post refreshing? 2) if the user hits F5, the page reloads and the code runs again, sending two or more times the same email. How can I avoid duplicated emails caused by manual browser refresh?

Code: Select all

<form name="fbrlink" action="<?= $_SERVER['PHP_SELF']."?page=ok" ?>" method="post">
<?php
echo('<input name="sbrlink" id="B1" type="button" value="broken Link?" style="border:none; background-color:#FFFFFF; font-family:Trebuchet MS; font-size:15px; font-weight:bold; color:#1A4877; cursor:pointer; display:block; text-decoration:underline;" onclick="this.form.submit();"/>');
?>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{ if ($_SERVER['QUERY_STRING'] == 'page=ok') {
echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>'; 
mail("contact@ctt.net","report broken link","Game notified:MarioBros");
echo '<script type="text/javascript" >document.fbrlink.sbrlink.disabled = true;</script>';
?> 
<script type="text/javascript" >document.fbrlink.action='<?php echo $a; ?>';
alert('<?php $_SERVER['QUERY_STRING'];?>');
</script>
<?php
}
else  {}
}else{
}
?>

Re: avoid duplicated mails on browser refresh

Posted: Mon Aug 02, 2010 12:24 pm
by PHPHorizons
Hello atomiccx,
is there any way to send mail without the post refreshing?
Ajax
How can I avoid duplicated emails caused by manual browser refresh?
Keep a log of which broken links have already been discovered and use that to prevent duplicate notifications.

Cheers

Re: avoid duplicated mails on browser refresh

Posted: Mon Aug 02, 2010 3:35 pm
by atomiccx
PHPHorizons, I don't know how to use Ajax, but I'm glad if you give me an example for the code below.

The 2nd suggestion I didn't get it. I need an implementation on the code.

Thanks.

Re: avoid duplicated mails on browser refresh

Posted: Wed Aug 04, 2010 6:55 am
by atomiccx
Hey PHP gurus! Please help me giving a solution for this problem.

Re: avoid duplicated mails on browser refresh

Posted: Wed Aug 04, 2010 7:01 am
by superdezign
Unless you have a problem that is really easy to solve (or, in my case, fun to solve), then you likely won't get us to write the code for you. If you don't know how to use AJAX, the next step would be to find out how. If you don't know how to check for duplicates in a database... You look at what is being submitted, and compare it with the data that has already been submitted.

Re: avoid duplicated mails on browser refresh

Posted: Wed Aug 04, 2010 2:52 pm
by atomiccx
I've read a lot of post about this topic, and it's a common thing that happens to web developers. I think it must have an easy way to solve it, but I new in PHP and don't how to implement it. Besides, I'm not using a database, if you read the code you can see that the script only sends an automated email to me.

Re: avoid duplicated mails on browser refresh

Posted: Wed Aug 04, 2010 5:23 pm
by superdezign
atomiccx wrote:I think it must have an easy way to solve it
[...]
I'm not using a database
If you've read a lot of posts, then you know that the most accepted format of handling multiple records of a similar format is to use the database. Besides... we already gave you solutions. All you have to do is Google it now.
atomiccx wrote:I new in PHP
[...]
if you read the code you can see [...]
Too messy to bother reading. For obvious reasons. ;)