加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php编程每天必学之验证码

发布时间:2020-12-12 21:21:39 所属栏目:PHP教程 来源:网络整理
导读:本文为大家分享了php图片验证码的实现代码,供大家参考研究具体内容如下 1.验证码图片生成 captcha.php //2.随机显示数字或字母 $captch_code = ""; for($i=0;$i4;$i++){ $fontsize=6; $fontcolor=imagecolorallocate($image,rand(0,120),120)); $da

本文为大家分享了php图片验证码的实现代码,分享给大家供大家参考,具体内容如下

1.验证码图片生成

captcha.php

//2.随机显示数字或字母
$captch_code = "";
for($i=0;$i<4;$i++){
$fontsize=6;
$fontcolor=imagecolorallocate($image,rand(0,120),120));
$data = "abcdefghijkmnpqrstuvwxy3456789";
$fontcontent =substr($data,strlen($data)),1);
$captch_code .=$fontcontent;
$x = ($i*100/4)+rand(5,10);
$y = rand(5,10);

imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
$_SESSION["authcode"] = $captch_code;

//3.增加干扰
//干扰点
for($i=0;$i<100;$i++){
$pointcolor=imagecolorallocate($image,rand(50,200),200));
imagesetpixel($image,rand(1,99),29),$pointcolor);
}

//干扰线
for($i=0;$i<2;$i++){
$linecolor=imagecolorallocate($image,rand(80,220),220));
imageline($image,$linecolor);
}

header("content-type:image/png");
imagepng($image);

2.页面实现验证码功能

form.php

?>

<!doctype html>
<html lang="en">

Document
验证码图片:

以上就是本文的全部内容,帮助大家轻松实现php图片验证码。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读