<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Tutorials Code Snippets and Php Tips &#187; captcha image</title>
	<atom:link href="http://readytousesolutions.com/phpblog/tag/captcha-image/feed/" rel="self" type="application/rss+xml" />
	<link>http://readytousesolutions.com/phpblog</link>
	<description>PHP tutorials - Examples of the most useful scripts</description>
	<lastBuildDate>Thu, 02 Sep 2010 05:23:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Tutorial : How to create a captcha image</title>
		<link>http://readytousesolutions.com/phpblog/php-tutorial-how-to-create-a-captcha-image/</link>
		<comments>http://readytousesolutions.com/phpblog/php-tutorial-how-to-create-a-captcha-image/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 13:30:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Usefull PHP]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[captcha code]]></category>
		<category><![CDATA[captcha image]]></category>
		<category><![CDATA[php captcha]]></category>
		<category><![CDATA[security code]]></category>
		<category><![CDATA[security image]]></category>
		<category><![CDATA[validate captcha]]></category>

		<guid isPermaLink="false">http://www.crivionweb.com/phpblog/?p=38</guid>
		<description><![CDATA[Hi, Are you tired of receiving spam messages from your contact forms or unwanted posts, robot accounts on your membership website? If yes, the solution is to create a php security image called captcha. That&#8217;s the best solution to secure &#8230; <a href="http://readytousesolutions.com/phpblog/php-tutorial-how-to-create-a-captcha-image/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi,<br />
Are you tired of receiving spam messages from your contact forms or unwanted posts, robot accounts on your membership website? If yes, the solution is to create a php security image called captcha. That&#8217;s the best solution to secure your web forms, etc. For creating a captcha security code you need to have GD-library installed and active on your webhost, but, most of the shared webhosts have this library installed. Here is the captcha code :</p>
<pre class="php">
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span>
<span class="phpComment">//The first step is to start a php session calling the special <span class="phpFunctionKeyword">function</span>
</span><span class="phpFunction">session_start</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//The seccond step is to generate a string randomly using <span class="phpFunction">rand</span> <span class="phpFunctionKeyword">function</span>
</span><span class="phpComment">//I<span class="phpString">'ll choose to get a random number <span class="phpNumber">6</span> numbers in length
</span>$randomcode <span class="phpOperator">=</span> <span class="phpFunction">rand</span><span class="phpOperator">(</span><span class="phpNumber">0</span>, 999999<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//Now we need a background image to write the random number to it
</span>$captchafromimage <span class="phpOperator">=</span> <span class="phpFunction">imagecreatefrompng</span><span class="phpOperator">(</span><span class="phpString">"captcha.png"</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//Setting font color
</span>$color <span class="phpOperator">=</span><span class="htmlText"> ImageColorAllocate </span><span class="phpOperator">(</span>$captchafromimage, 50, 50, 50<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//Ta da, here we are, writing the random generated code to the image
</span><span class="phpFunction">imagestring</span><span class="phpOperator">(</span>$captchafromimage, <span class="phpNumber">6</span>, 50, <span class="phpNumber">2</span>, $randomcode, $color<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//Now the random number is coded into <span class="phpFunction">md5</span> secure format
</span><span class="phpComment">//and stored it into a session name to be able to validate
</span><span class="phpComment">//it in the future
</span><span class="phpScriptVar">$_SESSION</span><span class="phpOperator">[</span>'</span><span class="htmlText">randomcode</span><span class="phpString">'<span class="phpOperator">]</span> <span class="phpOperator">=</span> <span class="phpFunction">md5</span><span class="phpOperator">(</span>$randomcode<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//Set up headers
</span><span class="phpFunction">header</span><span class="phpOperator">(</span><span class="phpString">"Content-type<span class="phpOperator">:</span> image/png"</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//Finally, let'</span>s show up the captcha image generated
</span><span class="phpFunction">imagepng</span><span class="phpOperator">(</span>$captchafromimage<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
</pre>
<p>You will need a background PNG image which you can download here (right click -> Save as)<br />
<img src="http://www.crivionweb.com/phpblog/wp-content/themes/default/images/captcha.png" alt="captcha image" /><br />
Here is the captcha result :<br />
<img src="http://www.crivionweb.com/phpblog/wp-content/themes/default/images/captcha.php" alt="php captcha" /></p>
]]></content:encoded>
			<wfw:commentRss>http://readytousesolutions.com/phpblog/php-tutorial-how-to-create-a-captcha-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
