All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
用动态网页技术PHP生成验证码图片的源代码_[PHP教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/17 7:46:29 Browse times: 409 Comment times: 0

用动态网页技术PHP生成验证码图片的源代码_[PHP教程]


Head photo

Go homepage
Upload pictures
Write articles

用动态网页技术PHP生成验证码图片的源代码_[PHP教程]

文件a.php

//checkNum.php
session_start();
function random(len)
{
srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();
strs="";
for(i=0;istrs.=srcstr[mt_rand(0,35)];
}
return strtoupper(strs);
}
str=random(4); //随机生成的字符串
width = 50; //验证码图片的宽度
height = 25; //验证码图片的高度
@header("Content-Type:image/png");
_SESSION["code"] = str;
//echo str;
im=imagecreate(width,height);
//背景色
back=imagecolorallocate(im,0xFF,0xFF,0xFF);
//模糊点颜色
pix=imagecolorallocate(im,187,230,247);
//字体色
font=imagecolorallocate(im,41,163,238);
//绘模糊作用的点
mt_srand();
for(i=0;i<1000;i++)
{
imagesetpixel(im,mt_rand(0,width),mt_rand(0,height),pix);
}
imagestring(im, 5, 7, 5,str, font);
imagerectangle(im,0,0,width-1,height-1,font);
imagepng(im);
imagedestroy(im);
_SESSION["code"] = str;
?>

文件b.php

session_start();
echo "";//生成图片
echo _SESSION["code"];//生成验证码值
?>





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.