• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

使用php实现加减法验证码

php 搞代码 4年前 (2022-01-22) 15次浏览 已收录 0个评论

这篇文章主要介绍了php实现的加减法验证码代码,可以使用10以内的加减法生成图片,需要的朋友可以参考下

<?php/*图片验证码文件,加减计算方式*/class ImageCode{ private $Jiashu  = 0;        //加数或者减数 private $JianShu = 0;        //被加数或者被减数 private $YunSuan = '';       //运算符 private $DeShu   = 0;        //得数 private $String  = '';       //字符串样式 private $Img;                //图片对象 private $Width   = 100;      //图片宽度 private $Height  = 50;       //图片高度 private $Ttf     = 'Num.ttf';//字体文件 private $Session = 'code';   //Session变量 private function JiaShu(){  header('Content-type:image/png');  $this -> Jiashu  = rand(1, 10);  $this -> JianShu = rand(1, 10);  $this -> YunSuan= $this -> Jiashu > $this -> JianShu ? '-' : '+';  $this -> DeShu   = $this -> Jiashu > $this -> JianShu ? $this -> Jiashu - $this -> JianShu : $this -> Jiashu + $this -> JianShu; } public fun<p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite>ction Show( $W = 100, $H = 50, $T = 'Num.ttf', $Code = 'code' ){  $this -> JiaShu();  $this -> String = $this -> Jiashu . $this -> YunSuan . $this -> JianShu . '= ? ';  $this -> Width  = $W;  $this -> Height = $H;  $this -> Ttf    = $T;  $this -> Session= $Code;  session_start();  $_SESSION[$this -> Session] = $this -> DeShu;  $this -> Images(); } private function Images(){  $this -> Img = imagecreate($this -> Width, $this -> Height);  $background_color = imagecolorallocate ($this -> Img, 255, 255, 255);  imagecolortransparent($this -> Img, $background_color);        imagettftext($this -> Img, 14, 0, 1, 20, imagecolorallocate ($this -> Img, 0, 0, 0), $this -> Ttf, $this -> String );  $this -> EchoImages(); } private function EchoImages(){  imagepng($this -> Img);  imagedestroy($this -> Img); }}$ImageCode = new ImageCode;$ImageCode -> Show(130, 35, 'Num.ttf', 'code');

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请随时关注我们网站!

相关推荐:

关于PHP求多项式导数的函数代码

关于PHP截取字符串的一些方法总结

以上就是使用php实现加减法验证码的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用php实现加减法验证码
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址