fazzfarrell Posted September 19, 2007 Share Posted September 19, 2007 Hi I have found some code for a php form, with a sectrity image which works fine as this: </code> <?php // check for posted form if (isset($_POST['login'])) { // see if the code the user typed matched the generated code if (strtoupper($_POST['code']) == $_SESSION['code']) { echo 'Congratulations, you entered the correct code.'; } else { echo 'You have entered the wrong code. Please <a href="contact2.php">try again</a>.'; } } else { ?> <form method="post" action="contact2.php"> <fieldset> <legend></legend> <label for="Name"> Send to: <select name="Email" id="Email"> <?php do { ?> <option value="<?php echo $row_rsContact['EMail']?>"><?php echo $row_rsContact['Manager']?></option> <?php } while ($row_rsContact = mysql_fetch_assoc($rsContact)); $rows = mysql_num_rows($rsContact); if($rows > 0) { mysql_data_seek($rsContact, 0); $row_rsContact = mysql_fetch_assoc($rsContact); } ?> </select> <br /> <br /> Name:</label> <input type="text" name="Name" id="Name" value="" /> <label for="Email">Email:</label> <input type="text" name="EMail" id="EMail" value="" /> <label for="Subject"> Subject:</label><input type="text" name="Subject" id="Subject" value="" /> <label for="Subject"> Message:</label> <textarea name="Message" rows="10" id="Message"></textarea> <div id="security"><img src="../security-image.php?width=144" width="144" height="30" alt="Security Image" /></div> <label for="code">Security Image:</label> <input type="text" name="code" id="code" value="" /> <input type="submit" name="login" id="login" value="Login" /> </fieldset> </form> <?php } ?><code> Which is great but does not send the message! Usually I send via <form method="post" action="wmdformmailer.php"> but od course this does not work! I have tried many ways to get it to work to no avail any one help? Link to comment https://forums.phpfreaks.com/topic/69867-solved-security-image/ Share on other sites More sharing options...
AdRock Posted September 19, 2007 Share Posted September 19, 2007 Here is my contact form <? // Change to your own email address $your_email = "[email protected]"; // This is what is displayed in the email subject line // Change it if you want $subject = "Message via your contact form"; // This is displayed when the email has been sent $thankyou_message = "<p>Thankyou. Your message has been sent.</p>"; $self = $_SERVER['REQUEST_URI']; $name = $_POST['txtName']; $email = $_POST['txtEmail']; $message = $_POST['txtMessage']; $send = $_POST['send']; $msg="<p>Please fill in this form if you have any queries or suggestions.</p>"; echo ($msg); $form = " <form method=\"post\" action=\"$self\"> <p><label for=\"txtName\">Name:</label> <input type=\"text\" title=\"Please enter your name\" id=\"txtName\" name=\"txtName\" size=\"40\" value=\"$name\" /></p> <p><label for=\"txtEmail\">Email:</label> <input type=\"text\" title=\"Please enter your email address\" id=\"txtEmail\" name=\"txtEmail\" size=\"40\" value=\"$email\"/></p> <p><label for=\"txtMessage\">Comments:</label> <textarea title=\"Please enter your message\" id=\"txtMessage\" name=\"txtMessage\" rows=\"20\" cols=\"45\">$message</textarea></p> <p>Please enter the text that you see in the image into the box below. You are asked to do this in order to verify that this message is not being performed by an automated process.</p> <p><label> </label></p> <div class=\"captcha\"><img src=\"includes/captcha.php\" alt=\"security image\" /></div> <p><label for=\"verify\">Anti-Spam key:</label> <input type=\"text\" title=\"Please enter the anti-spam key\" name=\"verify\" id=\"verify\" size=\"40\" /></p> <p><label> </label> <input type=\"submit\" class=\"sendbutton\" name=\"send\" value=\"Submit\" /></p> </form>"; if($send) { $valid=true; if( !$name ) { $errmsg.="Please enter your name:<br />"; $valid=false; } if( !$email ) { $errmsg.="Please enter your email address:<br />"; $valid=false; } else { $email = trim($email); $_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+"; $_host = "([-0-9A-Z]+\.)+"; $_tlds = "([0-9A-Z]){2,4}$/i"; if( !preg_match($_name."@".$_host.$_tlds,$email)) { $errmsg.="Email address has incorrect format!<br />"; $valid=false; } } if( !$message ) { $errmsg.="Please enter your message:<br />"; $valid=false; } if (empty($_POST['verify']) && $_POST['verify'] == $_SESSION['captchstr']) { $errmsg.="Please enter security image:<br />"; $valid=false; } } if( $valid !=true ) { echo( "<span style=\"font-weight: bold; color:red;\">".$errmsg."</span>" . $form ); } else { // Stop the form being used from an external URL // Get the referring URL $referer = $_SERVER['HTTP_REFERER']; // Get the URL of this page $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; // If the referring URL and the URL of this page don't match then // display a message and don't send the email. if ($referer != $this_url) { echo "You do not have permission to use this script from another URL.<br />"; echo "If you are behind a firewall please check your referrer settings."; exit; } // The URLs matched so send the email if( mail($your_email, $subject, $message, "From: $name <$email>")); { // Display the thankyou message echo $thankyou_message; } } ?> You need session_start() at the top of the page as always and you need to upload the arial.ttf to the same directory as this next bit that creates the securty image save this as captcha.php (i store this in a folder called includes with the arial.ttf) <?php session_start(); $strlength = rand(4,7); $captchastr = ""; for($i=1;$i<=$strlength;$i++) { $textornumber = rand(1,3); if($textornumber == 1) { $captchastr .= chr(rand(49,57)); } if($textornumber == 2) { $captchastr .= chr(rand(65,78)); } if($textornumber == 3) { $captchastr .= chr(rand(80,90)); } } $randcolR = rand(100,230); $randcolG = rand(100,230); $randcolB = rand(100,230); //initialize image $captcha is handle dimensions 200,50 $captcha = imageCreate(190,50); $backcolor = imageColorAllocate($captcha, $randcolR, $randcolG, $randcolB); $txtcolor = imageColorAllocate($captcha, ($randcolR - 60), ($randcolG - 60), ($randcolB - 60)); for($i=1;$i<=$strlength;$i++) { $clockorcounter = rand(1,2); if ($clockorcounter == 1) { $rotangle = rand(0,45); } if ($clockorcounter == 2) { $rotangle = rand(315,360); } //$i*25 spaces the characters 25 pixels apart imagettftext($captcha,rand(14,20),$rotangle,($i*25),30,$txtcolor,"/arial.ttf",substr($captchastr,($i-1),1)); } for($i=1; $i<=4;$i++) { imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$txtcolor); } for($i=1; $i<=4;$i++) { imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$backcolor); } //Send the headers (at last possible time) header('Content-type: image/png'); //Output the image as a PNG imagePNG($captcha); //Delete the image from memory imageDestroy($captcha); $_SESSION["captchastr"] = $captchastr ?> Link to comment https://forums.phpfreaks.com/topic/69867-solved-security-image/#findComment-351027 Share on other sites More sharing options...
fazzfarrell Posted September 19, 2007 Author Share Posted September 19, 2007 Thank you that is fantastic! Link to comment https://forums.phpfreaks.com/topic/69867-solved-security-image/#findComment-351062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.