ident Posted November 16, 2009 Share Posted November 16, 2009 I'm using a textbox called norobots This page formhandler uses emailhandle.php and we seem to be getting a high number of emails sent. So to stop robots using are site i added the textbox norobots. The verification is the users ip. and the textbox says add your ip address here. My problem is i dont know how to compare the textbox input to the users ip address. my code for handle email is below. If the ip's dont match i want it to go to a error page but if it matches i want it to send <?php //add the header include('header.php'); //define the receiver of the email $to = $_POST["to"]; //define the subject of the email $subject = htmlentities($_POST["subject"], ENT_QUOTES); //define the message to be sent. Each line should be separated with \n // http://www.simplecoders.com/showpic.php?f=IR6eC3zS2w41wA.jpg $url_bits = parse_url($_POST['rawlink']); if( !preg_match('/f=[a-z-A-Z0-9]+\.[a-z]{1,3}/', $url_bits['query']) ) { echo "bad link"; die; } $_POST['msg'] = str_replace('[iMAGE]', $_POST['rawlink'], $_POST['msg']); $message = htmlentities($_POST["msg"], ENT_QUOTES) . "\n\n\n\n******************************************\n\nFree image hosting at www.simplecoders.com\n\nThe Simple Coders Team "; $headers = "From: SimpleCoders\r\nReply-To: support@simplecoders"; //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); echo $mail_sent ? "<br /><center>Mail sent" : "Mail failed"; echo "<br /><a href=\"Upload.php\">Click here to go back to the previous page</a></center>"; ?> Quote Link to comment Share on other sites More sharing options...
cags Posted November 16, 2009 Share Posted November 16, 2009 You could use something like... if($_SERVER['REMOTE_ADDR'] == $_POST['user_ip']) { But I have to say I don't think it's a particularly good way of doing it, most people won't know what their IP address is. Quote Link to comment Share on other sites More sharing options...
sawade Posted November 16, 2009 Share Posted November 16, 2009 Another option is adding a captcha into the code to help prevent non-human submissions. Quote Link to comment Share on other sites More sharing options...
ident Posted November 16, 2009 Author Share Posted November 16, 2009 Hi. iv made it quite clear as picture shows. i have got this <?php // entered IP address $enteredIpaddress = $_POST['norobots']; // Actual IP address $usersIpaddress = $_SERVER['REMOTE_ADDR']; // GO COMPARE!!!!11111 if ($enteredIpaddress != $usersIPaddress) { // if wrong IP entered redirect to google or what ever! header('location: http://www.google.co.uk'); } else { // DO all this if the IP's match! //add the header include('header.php'); //define the receiver of the email $to = $_POST["to"]; //define the subject of the email $subject = htmlentities($_POST["subject"], ENT_QUOTES); //define the message to be sent. Each line should be separated with \n // http://www.simplecoders.com/showpic.php?f=IR6eC3zS2w41wA.jpg $url_bits = parse_url($_POST['rawlink']); if( !preg_match('/f=[a-z-A-Z0-9]+\.[a-z]{1,3}/', $url_bits['query']) ) { echo "bad link"; die; } $_POST['msg'] = str_replace('[iMAGE]', $_POST['rawlink'], $_POST['msg']); $message = htmlentities($_POST["msg"], ENT_QUOTES) . "\n\n\n\n******************************************\n\nFree image hosting at www.simplecoders.com\n\nThe Simple Coders Team "; $headers = "From: SimpleCoders\r\nReply-To: support@simplecoders"; //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); echo $mail_sent ? "<br /><center>Mail sent" : "Mail failed"; echo "<br /><a href=\"Upload.php\">Click here to go back to the previous page</a></center>"; } ?> but it always goes to google. Quote Link to comment Share on other sites More sharing options...
cags Posted November 16, 2009 Share Posted November 16, 2009 Variable names are case sensitive. You have Ipaddress in one and IPaddress later. Quote Link to comment Share on other sites More sharing options...
ident Posted November 16, 2009 Author Share Posted November 16, 2009 ah dodgy varible case had it as IP thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.