addtrain Posted August 22, 2007 Share Posted August 22, 2007 just wondering, but is there anyway i can do catchpa (those crazy letters) i put it here, but i really wanna do it with javascript, or html. can i put catchpa on my website?? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/66159-catchpa/ Share on other sites More sharing options...
tarun Posted August 22, 2007 Share Posted August 22, 2007 HTML and JavaScript That Would Be SO Easy For A Bot To Crack You Need To Use The PHP GD Library Just Search Google Quote Link to comment https://forums.phpfreaks.com/topic/66159-catchpa/#findComment-330923 Share on other sites More sharing options...
AdRock Posted August 22, 2007 Share Posted August 22, 2007 At the top of the page where you have the captcha you need to add <?php session_start(); To display the captch image you use something like <img src="captcha.php" alt="captcha image"> Where you have a text field to enter the captcha image text you need something like <input type="text" title="Please enter the image text" name="verify" id="verify" size="9" /> You have to compare what was entered in the text field and the actual captcha image top see if they match (this also checks ti make sure the field is not empty) if (empty($_POST['verify']) && $_POST['verify'] == $_SESSION['captchstr']) { //Display an error message or do whatever } and here is the code to generate the captcha image <?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(200,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; ?> You do however need a font such as arial.ttf in the same directory as the captcha.php file Quote Link to comment https://forums.phpfreaks.com/topic/66159-catchpa/#findComment-331243 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.