Home > php教程 > php手册 > php 验证码程序

php 验证码程序

WBOY
Release: 2016-06-13 09:48:27
Original
1234 people have browsed it

php 验证码程序 一款php 验证码程序函数,原理是利用php gd库再生成随便数字,然后创建一个session与一张数字图片,就成了图形验证码了。

php教程 验证码程序
一款php 验证码程序函数,原理是利用php gd库再生成随便数字,然后创建一个session与一张数字图片,就成了图形验证码了。
*/

function fun_code($sessionname)
{
 header("content-type:image/png");
 session_start();
 $authnum_session = '';
 //$str = 'abcdefghijkmnpqrstuvwxyz1234567890';
 $str = '1234567890';
 $l = strlen($str);
 for($i=1;$i  {
  $num=rand(0,$l-1);
  $authnum_session.= $str[$num];
 }
 $_session[$sessionname]=$authnum_session;
 srand((double)microtime()*1000000);
 $im = imagecreate(50,20);
 $black = imagecolorallocate($im, 0,0,0);
 $white = imagecolorallocate($im, 255,255,255);
 $gray = imagecolorallocate($im, 200,200,200);
 imagefill($im,68,30,$gray);
 for($i=0;$i  {
  imageline($im,rand(0,30),rand(0,21),rand(20,40),rand(0,21),$li);
 }
 imagestring($im, 5, 8, 2, $authnum_session, $white);
 for($i=0;$i  {
  imagesetpixel($im, rand()%70 , rand()%30 , $gray);
 }
 imagepng($im);
 imagedestroy($im);
}
echo fun_code("code");
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template