一個漂亮的PHP驗證碼
驗證碼在WEB應用中非常重要,通常用來防止使用者惡意提交表單,如惡意註冊和登入、論壇惡意灌水等。
自己可以匯入字型,可以按照自己的額需要隨便修改。
自己可以匯入字型,可以按照自己的額需要隨便修改。
一個漂亮的驗證碼,體現出網站的大方。
<span style="font-size:14px;"><?php
class Imagecode{
private $width ;
private $height;
private $counts;
private $distrubcode;
private $fonturl;
private $session;
function __construct($width = 120,$height = 30,$counts = 5,$distrubcode="1235467890qwertyuipkjhgfdaszxcvbnm",$fonturl="C:\Windows\Fonts\TektonPro-BoldCond.otf"){
$this->width=$width;
$this->height=$height;
$this->counts=$counts;
$this->distrubcode=$distrubcode;
$this->fonturl=$fonturl;
$this->session=$this->sessioncode();
session_start();
$_SESSION['code']=$this->session;
}
function imageout(){
$im=$this->createimagesource();
$this->setbackgroundcolor($im);
$this->set_code($im);
$this->setdistrubecode($im);
ImageGIF($im);
ImageDestroy($im);
}
private function createimagesource(){
return imagecreate($this->width,$this->height);
}
private function setbackgroundcolor($im){
$bgcolor = ImageColorAllocate($im, rand(200,255),rand(200,255),rand(200,255));//±³¾°ÑÕÉ«
imagefill($im,0,0,$bgcolor);
}
private function setdistrubecode($im){
$count_h=$this->height;
$cou=floor($count_h*2);
for($i=0;$i<$cou;$i++){
$x=rand(0,$this->width);
$y=rand(0,$this->height);
$jiaodu=rand(0,360);
$fontsize=rand(8,15);
$fonturl=$this->fonturl;
$originalcode = $this->distrubcode;
$countdistrub = strlen($originalcode);
$dscode = $originalcode[rand(0,$countdistrub-1)];
$color = ImageColorAllocate($im, rand(40,140),rand(40,140),rand(40,140));
imagettftext($im,$fontsize,$jiaodu,$x,$y,$color,$fonturl,$dscode);
}
}
private function set_code($im){
$width=$this->width;
$counts=$this->counts;
$height=$this->height;
$scode=$this->session;
$y=floor($height/2)+floor($height/4);
$fontsize=rand(30,35);
$fonturl="C:\Windows\Fonts\AdobeGothicStd-Bold.otf";//$this->fonturl;
$counts=$this->counts;
for($i=0;$i<$counts;$i++){
$char=$scode[$i];
$x=floor($width/$counts)*$i+8;
$jiaodu=rand(-20,30);
$color = ImageColorAllocate($im,rand(0,50),rand(50,100),rand(100,140));
imagettftext($im,$fontsize,$jiaodu,$x,$y,$color,$fonturl,$char);
}
}
private function sessioncode(){
$originalcode = $this->distrubcode;
$countdistrub = strlen($originalcode);
$_dscode = "";
$counts=$this->counts;
for($j=0;$j<$counts;$j++){
$dscode = $originalcode[rand(0,$countdistrub-1)];
$_dscode.=$dscode;
}
return $_dscode;
}
}
Header("Content-type: image/GIF");
$imagecode=new Imagecode(160,50);
$imagecode->imageout();
</span>
謝謝關注websites部落格!
相關文章
- 推薦一款漂亮的 Java 圖形驗證碼Java
- 很漂亮的Python驗證碼(記錄)Python
- 分享一款漂亮的 C# .Net 圖形驗證碼C#
- PHP驗證碼PHP
- PHP 驗證身份證號碼PHP
- PHP驗證碼的製作PHP
- 一個簡單的驗證碼工具
- PHP算式驗證碼和漢字驗證碼的實現方法PHP
- PHP行為驗證碼PHP
- PHP驗證碼淺析PHP
- python 驗證碼識別示例(一) 某個網站驗證碼識別Python網站
- 超簡單的PHP驗證碼識別PHP
- JS實現的一個驗證碼,可以在前端驗證後在提交actionJS前端
- 分享一個圖片驗證碼功能的實現
- 為網站實現一個驗證碼網站
- WebGeeker-Validation: 一個強大的 PHP 引數驗證器WebPHP
- PHP 攻擊簡訊驗證碼介面PHP
- PHP簡訊驗證碼防刷方案PHP
- 使用.Net Core實現的一個圖形驗證碼
- 一個非常好的行為驗證碼專案!
- 一對一聊天原始碼,驗證碼選擇輸入字母驗證原始碼
- 分享一個非常全的php正則驗證車牌格式的函式PHP函式
- php與js方式驗證手機號碼和郵件地址的合法性,js驗證身份證號碼PHPJS
- PHP中的郵箱驗證PHP
- carbon-一個能生成漂亮的程式碼截圖工具
- php短視訊原始碼,自動生成驗證碼,支援點選更換驗證碼數字PHP原始碼
- 一個oracle bug的簡單驗證Oracle
- PhpOffice 寫一個漂亮的表格PHP
- PHP實現隨機數字、字母的驗證碼功能PHP隨機
- 直播商城原始碼,驗證方式之一,滑塊驗證原始碼
- 驗證碼原理及驗證
- PHP 身份證精確匹配驗證PHP
- 隨機生成四個驗證碼隨機
- 面試一個漂亮女孩面試
- 5種PHP生成圖片驗證碼例項PHP
- 蘋果內購二次驗證 PHP程式碼蘋果PHP
- PHP版本的IP段驗證類PHP
- 把驗證碼做成射擊遊戲,這還是第一個!遊戲