php實(shí)現(xiàn)加減法驗(yàn)證碼代碼
<?php
/*圖片驗(yàn)證碼文件,加減計(jì)算方式*/
class ImageCode{
private $Jiashu = 0; //加數(shù)或者減數(shù)
private $JianShu = 0; //被加數(shù)或者被減數(shù)
private $YunSuan = ''; //運(yùn)算符
private $DeShu = 0; //得數(shù)
private $String = ''; //字符串樣式
private $Img; //圖片對(duì)象
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');
相關(guān)文章
php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
這篇文章主要介紹了如何在php與js中分別獲取客戶度mac地址的方法,需要的朋友可以參考下2013-07-07
深入mysql_fetch_row()與mysql_fetch_array()的區(qū)別詳解
本篇文章是對(duì)mysql_fetch_row()與mysql_fetch_array()的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
淺談laravel 5.6 安裝 windows上使用composer的安裝過程
今天小編就為大家分享一篇淺談laravel 5.6 安裝 windows上使用composer的安裝過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-10-10
Yii框架數(shù)據(jù)模型的驗(yàn)證規(guī)則rules()被執(zhí)行的方法
這篇文章主要介紹了Yii框架數(shù)據(jù)模型的驗(yàn)證規(guī)則rules()被執(zhí)行的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-12-12

