prcollin Posted July 6, 2007 Share Posted July 6, 2007 How do i create a security code that has to be entered by visualization before a form can be submitted to ward off spamming programs. Quote Link to comment Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 Your looking for a "CAPTCHA" .. Look in php freaks free souce code pretty sure theres a tutorial in there somewhere about it Quote Link to comment Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 www.google.com Search for PHP Captcha. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 6, 2007 Share Posted July 6, 2007 Have mine I made: <?php /* makeimg.php v1.00 ** Written by Ivan Oliver (11-Jun-2007) *******************************************************************************/ session_start(); $imgWidth=130; $imgHeight=34; $chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ'; $strText=''; for ($i=1;$i<7;$i++) {$strText.=substr($chars,mt_rand(0,strlen($chars)-1),1);} $_SESSION['vercode']=md5($strText); header("Content-type: image/png"); //$img=imagecreatetruecolor($imgWidth,$imgHeight); //22 $img=imagecreatefrompng('gfx/codebg.png'); $colBG=imagecolorallocate($img,0x11,0x11,0x11); $colFG=imagecolorallocate($img,255,255,255); for ($i=0;$i<strlen($strText);$i++) { $colFG=imagecolorallocate($img,mt_rand(50,255),mt_rand(50,255),mt_rand(50,255)); imagettftext($img,20,mt_rand(-40,40),10+($i*20),27,$colFG,'fonts/times.ttf',substr($strText,$i,1)); } imagepng($img); imagedestroy($img); ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 6, 2007 Share Posted July 6, 2007 btw... here it is in action: Refresh the page to see it change. EDIT: Forgot to mention that $chars has the character allowed in the code. Note that I removed some letters like lower case "L" and capital "O" to prevent them being confused with the numbers. You'll need to upload a TrueType font file (TTF) to the server (in thisd case, Times. Quote Link to comment Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 Yesideez with /fonts/time.ttf Can you use one thats off your computer? and if you know doesnt having such a file on your server create a security risk? just wondering Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 6, 2007 Share Posted July 6, 2007 Yes, upload one from C:\WINDOWS\Fonts\ or C:\WINNT\Fonts\ Just upload it in binary mode and be sure to point the PHP script to the right place. The script generates a PNG file for maximum quality with the image. No security risk - all it is is just a data file containg font information. Quote Link to comment Share on other sites More sharing options...
prcollin Posted July 6, 2007 Author Share Posted July 6, 2007 Have mine I made: <?php /* makeimg.php v1.00 ** Written by Ivan Oliver (11-Jun-2007) *******************************************************************************/ session_start(); $imgWidth=130; $imgHeight=34; $chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ'; $strText=''; for ($i=1;$i<7;$i++) {$strText.=substr($chars,mt_rand(0,strlen($chars)-1),1);} $_SESSION['vercode']=md5($strText); header("Content-type: image/png"); //$img=imagecreatetruecolor($imgWidth,$imgHeight); //22 $img=imagecreatefrompng('gfx/codebg.png'); $colBG=imagecolorallocate($img,0x11,0x11,0x11); $colFG=imagecolorallocate($img,255,255,255); for ($i=0;$i<strlen($strText);$i++) { $colFG=imagecolorallocate($img,mt_rand(50,255),mt_rand(50,255),mt_rand(50,255)); imagettftext($img,20,mt_rand(-40,40),10+($i*20),27,$colFG,'fonts/times.ttf',substr($strText,$i,1)); } imagepng($img); imagedestroy($img); ?> Thanks that saves me the programming time to figure out how to code it then writing it lol. 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.