PHP基于session图片验证码DEMO示例

所属分类: PHP源码-其它源码    2023-11-27 06:40:27

 21.2K  3  查看评论 (2)
PHP基于session图片验证码DEMO示例 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

PHP基于session图片验证码DEMO示例(共5个文件)

    • validatecode.class.php
    • captcha.php
    • index.php

使用方法

font = './font/elephant.ttf';//注意字体路径要写对,否则显示不了图片
 }
 //生成随机码
 private function createCode() {
  $_len = strlen($this->charset)-1;
  for ($i=0;$i<$this->codelen;$i++) {
   $this->code .= $this->charset[mt_rand(0,$_len)];
  }
 }
 //生成背景
 private function createBg() {
  $this->img = imagecreatetruecolor($this->width, $this->height);
  $color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));
  imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);
 }
 //生成文字
 private function createFont() {
  $_x = $this->width / $this->codelen;
  for ($i=0;$i<$this->codelen;$i++) {
   $this->fontcolor = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
   imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height / 1.4,$this->fontcolor,$this->font,$this->code[$i]);
  }
 }
 //生成线条、雪花
 private function createLine() {
  //线条
  for ($i=0;$i<6;$i++) { $color = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
   imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
  }
  //雪花
  for ($i=0;$i<100;$i++) { $color = imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
   imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
  }
 }
 //输出
 private function outPut() {
  header('Content-type:image/png');
  imagepng($this->img);
  imagedestroy($this->img);
 }
 //对外生成
 public function doimg() {
  $this->createBg();
  $this->createCode();
  $this->createLine();
  $this->createFont();
  $this->outPut();
 }
 //获取验证码
 public function getCode() {
  return strtolower($this->code);
 }
}

?>

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 其它源码

PHP体育篮球比赛直播录像视频导航网站源码

一款类似于直播吧篮球赛事录像网站,核心功能:后台可发布录像、直播、十佳球、站内搜索,实时更新比赛状态和比分情况。
  其它源码
 61226  0

原生PHP实现图片文件上传源码实例

一款php在线上传图片保存预览源码,选择本地图片,点击上传按钮,即可保存到服务器且返回显示图片。
  其它源码
 6921  0

PHP利用smtp类发送第三方邮件Demo示例

这是一款phpemail发邮件的php源码程序,填写完整的表单信息,提交后即可收到一封系统发出的邮件信息。
  其它源码
 2974  0

PHP党建空中课堂垃圾分类培训手机网站源码

这是一款手机微信公众号端的学习培训类网站,主要功能包含:按步骤推进学习显示内容、语音播放、倒计时阅读文章内容、填写表单信息等,所有内容都可通过后台管理系统进行操作。
  其它源码
 3814  0

评论数(2) 回复有机会获得K币 用户协议

    jq小菜鸡0
    2023-12-18 19:26:20
    下载就能用,支持!
    回复
    NoMeaning0
    2023-12-06 16:52:27
    这个非常不错,简单实用~ 轻松拿捏了😀
    回复 1
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论