- ·上一篇内容:xampp的apache启动不起来的解决方法
- ·下一篇内容:zend studio 7.2.0如何整合flex的功能
php验证码
网上搜罗也可以搜罗一大堆,但是代码都不是很优美,我个人就这么认为,因为刚开始写php,经常要去官网看看文档,php的文档真是个宝库,只要你花点时间看下,你就会发现很多优美的程序方法。这个验证码是我组织的:
<?php session_start(); // Generate a random character string function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890') { // Length of character list $chars_length = (strlen($chars) - 1); // Start our string $string = $chars{rand(0, $chars_length)}; // Generate random string for ($i = 1; $i < $length; $i = strlen($string)) { // Grab a random character from our list $r = $chars{rand(0, $chars_length)}; // Make sure the same two characters don't appear next to each other if ($r != $string{$i - 1}) $string .= $r; } // Return the string return $string; } $authnum_session=rand_str(4); $_SESSION["authnum_session"]=$authnum_session; //生成图片 $im=imagecreate(60,20); $blank=imagecolorallocate($im,0,0,0); $white=imagecolorallocate($im,255,255,255); $gray=imagecolorallocate($im,200,200,200); imagefill($im,68,30,$gray); $li=imagecolorallocate($im,220,220,220); for($j=0;$j<3;$j++){ imageline($im,rand(0,30),rand(0,21),rand(20,40),rand(0,21),$li); } for($z=0;$z<90;$z++){ imagesetpixel($im,rand()%70,rand()%30,$gray); } imagestring($im,5,12,5,$authnum_session,$white); header("Content-Type:image/png"); imagepng($im); ?>
本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论