<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[php验证码]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Fri, 22 Jun 2007 06:54:42 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	利用imagestring函数做的验证码，代码如下：<br/><div class="code"><br/>&lt;?PHP<br/>session_start();<br/>session_register(&#039;SafeCode&#039;);<br/>$type = &#039;gif&#039;;<br/>$width= 100;<br/>$height= 30;<br/>header(&quot;Content-type: image/&quot;.$type);<br/>srand((double)microtime()*1000000);<br/>$randval = randStr(4,&quot;&quot;);<br/>if($type!=&#039;gif&#039; &amp;&amp; function_exists(&#039;imagecreatetruecolor&#039;))&#123;<br/>$im = @imagecreatetruecolor($width,$height);<br/>&#125;else&#123;<br/>$im = @imagecreate($width,$height);<br/>&#125;<br/>$r = Array(225,211,255,223);<br/>$g = Array(225,236,237,215);<br/>$b = Array(225,236,166,125);<br/><br/>$key = rand(0,3);<br/><br/>$backColor = ImageColorAllocate($im,$r&#91;$key&#93;,$g&#91;$key&#93;,$b&#91;$key&#93;);//背景色（随机）<br/>$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色<br/>$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色<br/><br/>@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置<br/>@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置<br/>$stringColor = ImageColorAllocate($im, 255,51,153);<br/><br/>for($i=0;$i&lt;=100;$i++)&#123;<br/>$pointX = rand(2,$width-2);<br/>$pointY = rand(2,$height-2);<br/>@imagesetpixel($im, $pointX, $pointY, $pointColor);<br/>&#125;<br/><br/>@imagestring($im, 5, 5, 1, $randval, $stringColor);<br/>$ImageFun=&#039;Image&#039;.$type;<br/>$ImageFun($im);<br/>@ImageDestroy($im);<br/>$_SESSION&#91;&#039;SafeCode&#039;&#93; = $randval;<br/>//产生随机字符串<br/>function randStr($len=6,$format=&#039;ALL&#039;) &#123;<br/>switch($format) &#123;<br/>case &#039;ALL&#039;:<br/>$chars=&#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#039;; break;<br/>case &#039;CHAR&#039;:<br/>$chars=&#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&#039;; break;<br/>case &#039;NUMBER&#039;:<br/>$chars=&#039;0123456789&#039;; break;<br/>default :<br/>$chars=&#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#039;;<br/>break;<br/>&#125;<br/>$string=&quot;&quot;;<br/>while(strlen($string)&lt;$len)<br/>$string.=substr($chars,(mt_rand()%strlen($chars)),1);<br/>return $string;<br/>&#125;<br/>?&gt;<br/><br/></div><br/><br/>演示：<a href="http://jed.dzhope.com/aa.php" target="_blank">http://jed.dzhope.com/aa.php</a><br/><br/>利用imagettftext() 做的验证码<br/><div class="code"><br/>&lt;?PHP<br/>session_start();<br/>session_register(&#039;SafeCode&#039;);<br/>$type = &#039;gif&#039;;<br/>$width= 80;<br/>$height= 30;<br/>header(&quot;Content-type: image/&quot;.$type);<br/>srand((double)microtime()*1000000);<br/>$randval = randStr(4,&quot;&quot;);<br/>if($type!=&#039;gif&#039; &amp;&amp; function_exists(&#039;imagecreatetruecolor&#039;))&#123;<br/>$im = @imagecreatetruecolor($width,$height);<br/>&#125;else&#123;<br/>$im = @imagecreate($width,$height);<br/>&#125;<br/>$r = Array(225,211,255,223);<br/>$g = Array(225,236,237,215);<br/>$b = Array(225,236,166,125);<br/><br/>$key = rand(0,3);<br/><br/>$backColor = ImageColorAllocate($im,$r&#91;$key&#93;,$g&#91;$key&#93;,$b&#91;$key&#93;);//背景色（随机）<br/>$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色<br/>$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色<br/><br/>@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置<br/>@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置<br/>$stringColor = ImageColorAllocate($im, 255,51,153);<br/><br/>for($i=0;$i&lt;=100;$i++)&#123;<br/>$pointX = rand(2,$width-2);<br/>$pointY = rand(2,$height-2);<br/>@imagesetpixel($im, $pointX, $pointY, $pointColor);<br/>&#125;<br/><br/>///@imagestring($im, 5, 5, 1, $randval, $stringColor);<br/>////////////////////////////////////////// <br/>$font = &quot;SIMHEI.TTF&quot;;<br/>imagettftext($im, 20, 0, 10, 25, $stringColor, $font, $randval);<br/>//////////////////////////////////////<br/>$ImageFun=&#039;Image&#039;.$type;<br/>$ImageFun($im);<br/>@ImageDestroy($im);<br/>$_SESSION&#91;&#039;SafeCode&#039;&#93; = $randval;<br/>//产生随机字符串<br/>function randStr($len=6,$format=&#039;ALL&#039;) &#123;<br/>switch($format) &#123;<br/>case &#039;ALL&#039;:<br/>$chars=&#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#039;; break;<br/>case &#039;CHAR&#039;:<br/>$chars=&#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&#039;; break;<br/>case &#039;NUMBER&#039;:<br/>$chars=&#039;0123456789&#039;; break;<br/>default :<br/>$chars=&#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#039;;<br/>break;<br/>&#125;<br/>$string=&quot;&quot;;<br/>while(strlen($string)&lt;$len)<br/>$string.=substr($chars,(mt_rand()%strlen($chars)),1);<br/>return $string;<br/>&#125;<br/>?&gt;<br/><br/></div><br/><br/>演示：<a href="http://jed.dzhope.com/a.php" target="_blank">http://jed.dzhope.com/a.php</a>这个在windows平台下实验通过，linux没有通过。但是肯定是可以用的。<br/><br/>验证码的使用<br/><div class="code"><br/>&lt;img src=a.php align=absmiddle onclick=&quot;this.src=&#039;a.php?nocache=&#039;+Math.random()&quot; style=&quot;cursor:hand&quot;/&gt;<br/></div><br/>验证码可刷新<br/><br/>Tags - <a href="http://www.dzhope.com/tags/%25E9%25AA%258C%25E8%25AF%2581%25E7%25A0%2581/" rel="tag">验证码</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] php验证码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>