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

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

 51.1K  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简易的人才招聘求职类系统网站源码

一款招聘网站源码,该源码集成了两种会员类型:个人类型(投递简历)、企业类型(发布职位),各自都有不同的功能。主要功能:会员登录、会员注册、职位搜索、发布职位、投递简历、收藏简历等。
  其它源码
 1868  0

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

一款基于session缓存变量开发的验证码插件,共包含4个文件(ttf字体及三个php文件)使用了ttf字体,还有php生成背景、线条、雪花、文字、随机码,最后组合生成带有验证码的img图片。
  其它源码
 61113  0

PHP学校办公校园教务信息OA网站管理系统源码

这是一款校园数字化OA办公多用户管理系统,核心功能:包含4个用户组角色(总管理员、老师、学生、图书管理员)、可在线管理学生信息、老师信息、请假、借书、发布公告等校内日常事务。
  其它源码
 2897  0

PHP支持同时上传多张图片的图片管理系统源码

一款在线图片管理系统网站源码,核心功能:单次可上传多张图片、选择本地图片后可预览、上传至服务器指定文件夹,图片列表展示。
  其它源码
 71733  0

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

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