Home > php教程 > php手册 > body text

PHP实现简单汉字验证码

WBOY
Release: 2016-06-06 19:49:54
Original
911 people have browsed it

大家知道简单数字或者字母验证码很容易被破解,但是算式验证码或者中文汉字验证码不容易被破解,所以建议大家在使用验证码的时候,尽量用算式验证码或者中文汉字

现在越来越多的网站都开始使用汉字验证码了,既增加了我们国人的亲切感,同时也增加了机器破解的难度,,这里我就简单粗暴的说一下。。。

创建背景画布

$image = imagecreatetruecolor(200, 60); $background = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $background);

画干扰点

for ($i=0; $i

画干扰线

//4条水平线 for ($i=0; $i

画汉字

$text = array('栀', '子', '花', '开'); for ($i=0; $i

这里注意一下,字体文件一定要支持中文的

编码要使用utf-8,gbk的中文记得要转吗【iconv函数可以帮助你】

输出图像

header("Content-Type:image/png"); imagepng($image);

销毁资源

imagedestroy($image);

经过粗略的搞吧搞吧,中文验证码也就显示出来了,当然一般网站使用的时候会有一个汉字库种子,从里面随机取出特定个数的汉字显示,最后就是记录到session进行验证了。

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!