• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP图片验证码验证

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

*.html

<input type="text" name="captcha" id="captcha" placeholder="验证码" maxlength="10">
                    <img src="captcha.php"  onclick="this.src='captcha.php?' + Math.random();" width="105" height="36">

 

api.php

<?php
session_start();

$dataObj = json_decode($HTTP_RAW_POST_DATA);
if(strtolower($_SESSION["code"]) != strtolower($dataObj->captcha)){   
    $msg = '不正确';    
}else{
//正确
}

 

captcha.php
<?php
session_start();
header ('Content-Type: image/png');

$image=imagecreatetruecolor(100, 30);
//背景颜色为白色
$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 20, 20, $color);

$code='';
for($i=0;$i<4;$i++){
    $fontSize=8;
    $x=rand(5,10)+$i*100/4;
    $y=rand(5, 15);
    // $data='abcdefghijklmnpqrstuvwxyz123456789';
    $data='ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789';
    $string=substr($data,rand(0, strlen($data)),1);
    $code.=$string;
    $color=imagecolorallocate($image,rand(0,120), rand(0,120), rand(0,120));
    imagestring($image, $fontSize, $x, $y, $string, $color);
}
$_SESSION['code']=$code;//存储在session里

for($i=0;$i<200;$i++){
    $pointColor=imagecolorallocate($image, rand(100, 255), rand(100, 255), rand(100, 255));
    imagesetpixel($image, rand(0, 100), rand(0, 30), $pointColor);
}
for($i=0;$i<2;$i++){
    $linePoint=imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255));
    imageline($image, rand(10, 50), rand(10, 20), rand(80,90), rand(15, 25), $linePoint);
}
imagepng($image);
imagedestroy($image);

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP相对完整的分页发布时间:2022-07-10
下一篇:
PHP格式化显示时间date()函数【转】发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap