acidglitter Posted April 14, 2006 Share Posted April 14, 2006 i have a form at my website and i don't want it to get abused by spam. i was thinking maybe i should have a verification thing where you have to enter the 5 or 6 random numbers that show up. how could i do that? Link to comment https://forums.phpfreaks.com/topic/7442-random-numbers/ Share on other sites More sharing options...
AndyB Posted April 14, 2006 Share Posted April 14, 2006 Search for captcha to find something you like. I have a downloadable script set at [a href=\"http://www.digitalmidget.com/php_noob/captcha.php\" target=\"_blank\"]http://www.digitalmidget.com/php_noob/captcha.php[/a] that might be useful. Link to comment https://forums.phpfreaks.com/topic/7442-random-numbers/#findComment-27099 Share on other sites More sharing options...
underparnv Posted April 14, 2006 Share Posted April 14, 2006 Since I'm in a good mood...and it's Friday! :)image.php[code]<?phpsession_start();// make a string with all the characters that we// want to use as the verification code$alphanum = "ABCDEFGHJKLMNPQRTWXYZ2345689";// generate the verication code// change the last digit in this function for the length of string you would like$rand = substr(str_shuffle($alphanum), 0, 4);// create an image object using the chosen background// email me at [email protected] for this background image$image = imagecreatefrompng("background3.png");$textColor = imagecolorallocate ($image, 0, 0, 0);// write the code on the background imageimagestring ($image, 5, 5, 8, $rand, $textColor);// create the hash for the verification code// and put it in the session$_SESSION['image_random_value'] = md5($rand);// send several headers to make sure the image is not cached// taken directly from the PHP Manual// Date in the pastheader("Expires: Mon, 26 Jul 1997 05:00:00 GMT");// always modifiedheader("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// HTTP/1.1header("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);// HTTP/1.0header("Pragma: no-cache");// send the content type header so the image is displayed properlyheader('Content-type: image/jpeg');// send the image to the browserimagejpeg($image);// destroy the image to free up the memoryimagedestroy($image);?>[/code]register.php (or whatever the name of your page with the registration form on it would be)[code]<?phpsession_start();echo "<form action=\"form_handler.php\" method=\"post\"><b>Human Verification:</b><br />Input the text you see in this image. <b>This is case sensitive</b>!<br /><img src=\"image.php\" alt=\"Verification Image\" title=\"Verification Image\" /><br /><input type=\"text\" name=\"human\" size=\"5\" /><br /><br /><h2>Submit Form</h2><hr><br /><input type=\"submit\" value=\"Submit\" /></form>";?>[/code]form_handler.php[code]<?php$human = $_POST["human"];if (md5($human) != $_SESSION["image_random_value"]) { echo "Invalid human verification image entry!";} else { echo "Validation passes";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/7442-random-numbers/#findComment-27107 Share on other sites More sharing options...
acidglitter Posted June 3, 2006 Author Share Posted June 3, 2006 thats awesome. thanks! :)i shortened it all to one page and it works, but im wondering if spammers could get through it because of how i changed it? and where should the $rand be md5'd? on page 1 or 2?[code]<?phpif(!$_GET['p']==2){$alphanum="ABCDEFGHJKLMNPQRTWXYZ2345689";$rand=substr(str_shuffle($alphanum), 0, 4);$random=md5($rand);echo "<form action=\"kk.php?p=2\" method=\"post\">$rand<br /><input type=\"text\" name=\"human\" size=\"5\" /><input type=\"hidden\" name=\"random\" value=\"$random\"><input type=\"submit\" value=\"Submit\" /></form>";} else {$random=$_POST['random'];$human = $_POST["human"];if (md5($human) != $random) { echo "Invalid human verification image entry!";} else { echo "Validation passes";}} ?>[/code] Link to comment https://forums.phpfreaks.com/topic/7442-random-numbers/#findComment-41517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.