I have a directory and I would like to add the captcha code or something similar to stop spammers. Can anyone help me out? Thanks!
Ok, basic captcha: You need a server-side way to store what the image represents. Usually that's called a "session". So, you display a picture with random letters/numbers, you also generate a random image name, and display it on a form. Record on the "session" the generated text for the image and its filename. On this form, you will pass as a "hidden" input field with the image file name. Then, when you process the form, you compare what the user has typed with what you have on your server session.
The problem with this is, if the image name is actually stored, and the image name is the answer to the question, the bot will be able to read this. Be careful!!
add this in your form <input name="verify" size="6" type="text" maxlength="6" /> <img align="absmiddle" src="/includes/secimage.php" /> verication if the code are correct after form submited if(!isset($_SESSION['img_verification']) || trim($_POST['verify']) != $_SESSION['img_verification']) { $_fperror="Sorry wrong code"; } remeber you need to start a session to script work ! SEC IMAGE CODE <?php $num_chars=6; // ==================== $chrs = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); session_start(); unset($_SESSION['img_verification']); if(!isset($_SESSION['img_verification'])) { $string=""; for($n=0;$n<$num_chars;$n++) { $string.=$chrs[rand(0,36)]; } $_SESSION['img_verification']=$string; } header("Content-type: image/png\n\n"); // Image header $im = imagecreate(84,20); $bg = imagecolorallocate($im, 255, 255, 255); $line = imagecolorallocate($im, 216,216,216); // Draw random lines for($i=0;$i<=100;$i++) { imageline($im, rand(1,170), rand(1,170), rand(1,100), rand(1,100),$line); } // Text color array $text_color_array=array("255,51,0","0,0,0","51,0,204","204,51,102","102,102,102","0,153,0"); for($n=0;$n<$num_chars;$n++) { // Break the color into R, G and B $text_color=$text_color_array[rand(0,count($text_color_array)-1)]; $text_color=explode(",", $text_color); $text = imagecolorallocate($im, $text_color[0], $text_color[1], $text_color[2]); // Text color imagestring ($im,50, 10+($n*10), 3, substr($string, $n, 1), $text); // Write the text } imagepng($im); imagedestroy($im); ?> PHP:
well here goes my first post. in another forum someone posted they needed to add captcha to a form due to spamming. i was interested as i wanted something like that also. he provided a tell a friend script and the location on the internet for captcha, well i couldn't do it with captcha but i found something called "auditor" and i was able to apply it. you can see it at: http://www.american-builder.com/test/recommend.php i'll try and attach the "auditor" zip file. i didn't wrire these php scripts, i just mashed them together.