Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
[TUT] How to create a Captcha image & form
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Markshall" data-source="post: 51618" data-attributes="member: 1872"><p>Earlier on today I create a video-tutorial on how to create your very own captcha image & form, and this is the result:</p><p></p><p>[media="YOUTUBE"]fDolfH3gY10[/media]</p><p></p><p>If you can't be bothered watching the video and just want the code:</p><p></p><p><strong>index.php</strong></p><p>[php]<?php</p><p>session_start();</p><p></p><p>if ( isset( $_POST['submit'] ) )</p><p>{</p><p>$code = strip_tags( $_POST['code'] );</p><p>$real_code = $_SESSION['captcha_code'];</p><p>if ( $code !== $real_code )</p><p>{</p><p>echo "Wrong code! Code was {$real_code}";</p><p>}</p><p>else</p><p>{</p><p>echo "Correct code!";</p><p>}</p><p>}</p><p>else</p><p>{</p><p>?></p><p><form method="post"></p><p><img src="captcha.php" /><br /></p><p>Enter code: <input type="text" name="code" /> <input type="submit" name="submit" value="Go" /></p><p></form></p><p><?php</p><p>}</p><p>?>[/php]</p><p></p><p><strong>captcha.php</strong></p><p>[php]<?php</p><p>/* This tutorial will teach you how to create your own Captcha image. */</p><p></p><p>session_start();</p><p>$chars = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";</p><p>$length = ( isset( $_GET['l'] ) && is_numeric( $_GET['l'] ) ) ? (int)$_GET['l'] : 8;</p><p></p><p>$captcha = "";</p><p>for ( $i = 1; $i <= $length; $i++ )</p><p>{</p><p>$captcha .= $chars[ mt_rand( 0, strlen( $chars ) ) ];</p><p>}</p><p></p><p>$_SESSION['captcha_code'] = $captcha;</p><p></p><p>$width = ( $length * 10 ) - 3;</p><p>$img = imagecreate( $width, 17 );</p><p>$bg = imagecolorallocate( $img, 0, 0, 0 ); //black</p><p>$txt = imagecolorallocate( $img, 255, 255, 255 ); //white</p><p>imagestring( $img, 5, 3, 1, $captcha, $txt );</p><p></p><p>header( "Content-Type: image/PNG" );</p><p>imagepng( $img );</p><p>imagedestroy( $img );</p><p>?>[/php]</p></blockquote><p></p>
[QUOTE="Markshall, post: 51618, member: 1872"] Earlier on today I create a video-tutorial on how to create your very own captcha image & form, and this is the result: [media="YOUTUBE"]fDolfH3gY10[/media] If you can't be bothered watching the video and just want the code: [b]index.php[/b] [php]<?php session_start(); if ( isset( $_POST['submit'] ) ) { $code = strip_tags( $_POST['code'] ); $real_code = $_SESSION['captcha_code']; if ( $code !== $real_code ) { echo "Wrong code! Code was {$real_code}"; } else { echo "Correct code!"; } } else { ?> <form method="post"> <img src="captcha.php" /><br /> Enter code: <input type="text" name="code" /> <input type="submit" name="submit" value="Go" /> </form> <?php } ?>[/php] [b]captcha.php[/b] [php]<?php /* This tutorial will teach you how to create your own Captcha image. */ session_start(); $chars = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; $length = ( isset( $_GET['l'] ) && is_numeric( $_GET['l'] ) ) ? (int)$_GET['l'] : 8; $captcha = ""; for ( $i = 1; $i <= $length; $i++ ) { $captcha .= $chars[ mt_rand( 0, strlen( $chars ) ) ]; } $_SESSION['captcha_code'] = $captcha; $width = ( $length * 10 ) - 3; $img = imagecreate( $width, 17 ); $bg = imagecolorallocate( $img, 0, 0, 0 ); //black $txt = imagecolorallocate( $img, 255, 255, 255 ); //white imagestring( $img, 5, 3, 1, $captcha, $txt ); header( "Content-Type: image/PNG" ); imagepng( $img ); imagedestroy( $img ); ?>[/php] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
[TUT] How to create a Captcha image & form
Top