国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php實現加減法驗證碼代碼

2024-05-04 23:21:18
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


<?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 function 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');

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金门县| 伊宁县| 衡阳县| 汉源县| 白玉县| 那坡县| 上饶市| 巴南区| 凤凰县| 襄垣县| 海盐县| 永登县| 蓬莱市| 卓尼县| 平阴县| 定南县| 凭祥市| 贵州省| 漳州市| 开原市| 宜良县| 广宗县| 郑州市| 禄丰县| 呼和浩特市| 吴江市| 罗山县| 大港区| 绥滨县| 泸溪县| 鲁山县| 交城县| 康平县| 安国市| 宜城市| 行唐县| 长海县| 平遥县| 桐城市| 汤阴县| 荥经县|