Forum Moderators: coopster
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; }
This one is at the end of my mail() string and I am supposed to list in it the name of the page with the php in it. But when I change it to anything it doesn't seem to matter. It all still sends.
"X-Mailer: chemailphp.php 2.07"
I personally like Dreamcatcher's Solution:
Another easy solution and less server intense than the Captcha is to create a random simple sum and have people enter the total in a text box. I`ve found this to be very effective indeed.
;)
Good luck!
Anyone have the code for if it isn't sent from the form page?
Also, any idea what this does? I don't understand it.
if ($_POST['token']!= $_SESSION['token'])
If the mail script was called remotely i.e. NOT from the website the form was residing on, the $_POST['token'] would be an empty string, as well as $_SESSION['token']... so the IF statement would evaluate as true and would be allowed.
You should therefore add at the begining:
if ($_POST['token']=="") exit; // who sent you here without a token?!?!
1. Generate a random string and send it as a cookie to the user when he arrives the contact page.
2. Include the cookie value as a hidden field in the post form
3. In the processing part, check for the existence of the post variable and the cookie and that they match. Send the mail only if they do.
Have a nice day!
Page with the form:
<?php
$code = md5(microtime());
setcookie("botcheck", $code);
?><form method="post" action="sendmail.php">
<!-- Your form elements here -->
<input type="hidden" name="botcheck" value="<?php echo $code;?>">
</form>
sendmail.php
<?php
if ($_COOKIE['botcheck'] && $_POST['botcheck'] == $_COOKIE['botcheck'])
{
// Send mail here
}
?>
As I had told, it is not the best spam protection method but it can definitely provide some amount of security. Maybe you can give it a try and see how the results are?