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. Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/ 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 Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291256 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 www.google.com Search for PHP Captcha. Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291258 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); ?> Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291269 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. Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291270 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 Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291275 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. Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291278 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. Link to comment https://forums.phpfreaks.com/topic/58721-security-code-question/#findComment-291352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.