国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
PHP生成制作驗(yàn)證碼的簡單實(shí)例,php驗(yàn)證碼實(shí)例
首頁 后端開發(fā) php教程 PHP生成制作驗(yàn)證碼的簡單實(shí)例,php驗(yàn)證碼實(shí)例_PHP教程

PHP生成制作驗(yàn)證碼的簡單實(shí)例,php驗(yàn)證碼實(shí)例_PHP教程

Jul 12, 2016 am 08:49 AM
php 手機(jī)號 生成 驗(yàn)證碼

PHP生成制作驗(yàn)證碼的簡單實(shí)例,php驗(yàn)證碼實(shí)例

看完就會,不會你打我,話不多說、開搞(人狠話不多

1.0 首先先看代碼

<&#63;php
header("Content-Type:text/html;Charset=UTF-8");// 設(shè)置頁面的編碼風(fēng)格
header("Content-Type:image/jpeg");// 通知瀏覽器輸出的是jpeg格式的圖像

$img = imagecreatetruecolor(150,50);//創(chuàng)建畫布并設(shè)置大小 x軸150 y軸50

$bgcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));//分配背景顏色
imagefill($img, 0, 0, $bgcolor); ////把背景填充到圖像
imagejpeg($img);       // 輸出圖像
imagedestroy($img);     // 銷毀圖像
&#63;>

好,現(xiàn)在結(jié)合以上代碼,來分析分析以上用到的幾個(gè)函數(shù):

① imagecreatetruecolor();

imagecreatetruecolor — 新建一個(gè)真彩色圖像(感覺哇,那么長,其實(shí)仔細(xì)一看挺好記的 image/create/true/color,什么是真彩色圖像?往下看)

 resource imagecreatetruecolor ( int $width , int $height )

imagecreatetruecolor() 和 imagecreate()兩個(gè)函數(shù)都能創(chuàng)建畫布

resource imagecreate ( int $x_size , int $y_size )

imagecreatetruecolor()建立的是一幅大小為 x和 y的黑色圖像(默認(rèn)為黑色[即便叫法就是真彩色圖像]),如想改變背景顏色則需要用填充顏色函數(shù) imagefill($img,0,0,$color);

imagecreate 新建一個(gè)空白圖像資源,用imagecolorAllocate()添加背景色

上面兩個(gè)函數(shù)只不過是一個(gè)功能的兩種方法

② imagecolorallocate();

imagecolorallocate — 為一幅圖像分配顏色

int imagecolorallocate ( resource $image , int $red , int $green , int $blue )

顏色分別用 紅 綠 藍(lán)三色組合,這些參數(shù)是 0 到 255 的整數(shù)或者十六進(jìn)制的 0x00 到 0xFF。

③ mt_rand();

mt_rand — 生成更好的隨機(jī)數(shù)

int mt_rand ( int $min , int $max )

$min 可選的、返回的最小值(默認(rèn):0)  $max 可選的、返回的最大值(默認(rèn):mt_getrandmax())

這里就是用來讓他隨機(jī)生成背景顏色,0-255隨便取值。所以頁面沒刷新一次畫布背景顏色就不一樣。

效果圖:

2.0 開始往里面做干擾線,干擾點(diǎn)。防止驗(yàn)證圖像被秒識別

<&#63;php
header("Content-Type:text/html;Charset=UTF-8");// 設(shè)置頁面的編碼風(fēng)格
header("Content-Type:image/jpeg");// 通知瀏覽器輸出的是jpeg格式的圖像

$img = imagecreatetruecolor(150,50);//創(chuàng)建畫布并設(shè)置大小 x軸150 y軸50

$bgcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));//分配背景顏色

//添加干擾線,并循環(huán)3次,背景顏色隨機(jī)
for($i=0;$i<3;$i++){

  $linecolor = imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  imageline($img, mt_rand(0,150), mt_rand(0,50), mt_rand(0,150), mt_rand(0,50), $linecolor);

}
//添加干擾點(diǎn),并循環(huán)25次,背景顏色隨機(jī)
for($i=0;$i<25;$i++){

  $dotcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
  imagesetpixel($img, mt_rand(0,150), mt_rand(0,60), $dotcolor);

}

imagefill($img, 0, 0, $bgcolor); ////把背景填充到圖像
imagejpeg($img);       // 輸出圖像
imagedestroy($img);     // 銷毀圖像
&#63;>

函數(shù)分析:

① imageline();

imageline — 畫一條線段

bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )

imageline() 用 color 顏色在圖像 image 中從坐標(biāo) x1,y1 到 x2,y2(圖像左上角為 0, 0)畫一條線段。

imageline($img, mt_rand(0,150), mt_rand(0,50), mt_rand(0,150), mt_rand(0,50), $linecolor);這里意思就是 畫布$img 中從坐標(biāo) x1,y1 到 x2,y2隨機(jī)

② imagesetpixel();

imagesetpixel— 畫一個(gè)單一像素

bool imagesetpixel ( resource $image , int $x , int $y , int $color )imagesetpixel() 在 image 圖像中用 color 顏色在 x,y 坐標(biāo)(圖像左上角為 0,0)上畫一個(gè)點(diǎn)。

imagesetpixel($img, mt_rand(0,150), mt_rand(0,60), $dotcolor);具體含義同上 效果圖:

3.0 添加驗(yàn)證字母數(shù)字

<&#63;php
header("Content-Type:text/html;Charset=UTF-8");// 設(shè)置頁面的編碼風(fēng)格
header("Content-Type:image/jpeg");// 通知瀏覽器輸出的是jpeg格式的圖像

$img = imagecreatetruecolor(150,50);//創(chuàng)建畫布并設(shè)置大小 x軸150 y軸50

$bgcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));//分配背景顏色

//添加干擾線,并循環(huán)3次,背景顏色隨機(jī)
for($i=0;$i<3;$i++){

  $linecolor = imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  imageline($img, mt_rand(0,150), mt_rand(0,50), mt_rand(0,150), mt_rand(0,50), $linecolor);

}
//添加干擾點(diǎn),并循環(huán)25次,背景顏色隨機(jī)
for($i=0;$i<25;$i++){

  $dotcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
  imagesetpixel($img, mt_rand(0,150), mt_rand(0,60), $dotcolor);

}

//添加需要驗(yàn)證的字母或者數(shù)字
$rand_str = "qwertyuiopasdfghjklzxcvbnm1234567890";//需要使用到驗(yàn)證的一些字母和數(shù)字
$str_arr = array();  //命名一個(gè)數(shù)組
for($i = 0;$i<4;$i++){  //循環(huán)4次,就是有四個(gè)隨機(jī)的字母或者數(shù)字              
  $pos = mt_rand(0,strlen($rand_str)-1);
  $str_arr[] = $rand_str[$pos];//臨時(shí)交換
}

$x_start=150/4;//單個(gè)字符X軸位置

foreach ($str_arr as $key) {
  $fontcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
  imagettftext($img, 25, mt_rand(-15,15), $x_start, 50/2, $fontcolor, "C:/Windows/Fonts/Verdana.TTF", $key);
  $x_start +=20;//遍歷后單個(gè)字符沿X軸 +20
}

imagefill($img, 0, 0, $bgcolor); ////把背景填充到圖像
imagejpeg($img);       // 輸出圖像
imagedestroy($img);     // 銷毀圖像
&#63;>

函數(shù):

imagettftext();

imagettftext — 用 TrueType 字體向圖像寫入文本

 array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

分析下面的代碼:

imagettftext($img, 25, mt_rand(-15,15), $x_start, 50/2, $fontcolor, "C:/Windows/Fonts/Verdana.TTF", $key);

$img-----------畫布

25-----------字體的尺寸。

mt_rand(-15,15)----------角度制表示的角度,0 度為從左向右讀的文本。更高數(shù)值表示逆時(shí)針旋轉(zhuǎn)。例如 90 度表示從下向上讀的文本。(就是字體角度的問題,)

$x_start----------通俗易懂的講就是字符的X軸位置

50/2----------字符的高度

$fontcolor----------字符顏色

"C:/Windows/Fonts/Verdana.TTF"----------字符的字體樣式路徑

$key-----------遍歷出后的字符

效果:

看起來還是挺可愛的。

以上這篇PHP生成制作驗(yàn)證碼的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持幫客之家。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1136662.htmlTechArticlePHP生成制作驗(yàn)證碼的簡單實(shí)例,php驗(yàn)證碼實(shí)例 看完就會,不會你打我,話不多說、開搞( 人狠話不多 ) 1.0 首先先看代碼 phpheader("Content...
本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

為什么我們評論:PHP指南 為什么我們評論:PHP指南 Jul 15, 2025 am 02:48 AM

PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

如何在Windows上安裝PHP 如何在Windows上安裝PHP Jul 15, 2025 am 02:46 AM

安裝PHP在Windows上的關(guān)鍵步驟包括:1.下載合適的PHP版本并解壓,推薦使用ThreadSafe版本配合Apache或NonThreadSafe版本配合Nginx;2.配置php.ini文件,將php.ini-development或php.ini-production重命名為php.ini;3.將PHP路徑添加到系統(tǒng)環(huán)境變量Path中以便命令行使用;4.測試PHP是否安裝成功,通過命令行執(zhí)行php-v和運(yùn)行內(nèi)置服務(wù)器測試解析能力;5.若使用Apache,需在httpd.conf中配置P

PHP語法:基礎(chǔ)知識 PHP語法:基礎(chǔ)知識 Jul 15, 2025 am 02:46 AM

PHP的基礎(chǔ)語法包括四個(gè)關(guān)鍵點(diǎn):1.PHP標(biāo)簽必須使用結(jié)束,推薦使用完整標(biāo)簽;2.輸出內(nèi)容常用echo和print,其中echo支持多參數(shù)且效率更高;3.注釋方式有//、#和//,用于提升代碼可讀性;4.每條語句必須以分號結(jié)尾,空格和換行不影響執(zhí)行但影響可讀性。掌握這些基本規(guī)則有助于寫出清晰穩(wěn)定的PHP代碼。

python如果還有示例 python如果還有示例 Jul 15, 2025 am 02:55 AM

寫Python的ifelse語句關(guān)鍵在于理解邏輯結(jié)構(gòu)與細(xì)節(jié)。1.基礎(chǔ)結(jié)構(gòu)是if條件成立執(zhí)行一段代碼,否則執(zhí)行else部分,else可選;2.多條件判斷用elif實(shí)現(xiàn),順序執(zhí)行且一旦滿足即停止;3.嵌套if用于進(jìn)一步細(xì)分判斷,建議不超過兩層;4.簡潔場景可用三元表達(dá)式替代簡單ifelse。注意縮進(jìn)、條件順序及邏輯完整性,才能寫出清晰穩(wěn)定的判斷代碼。

PHP 8安裝指南 PHP 8安裝指南 Jul 16, 2025 am 03:41 AM

在Ubuntu上安裝PHP8的步驟為:1.更新軟件包列表;2.安裝PHP8及基礎(chǔ)組件;3.檢查版本確認(rèn)安裝成功;4.按需安裝額外模塊。Windows用戶可下載ZIP包并解壓,隨后修改配置文件、啟用擴(kuò)展并將路徑加入環(huán)境變量。macOS用戶推薦使用Homebrew安裝,依次執(zhí)行添加tap、安裝PHP8、設(shè)置默認(rèn)版本及驗(yàn)證版本等步驟。不同系統(tǒng)下安裝方式雖有差異,但流程清晰,根據(jù)用途選對方法即可。

什么是PHP,它是用什么? 什么是PHP,它是用什么? Jul 16, 2025 am 03:45 AM

PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

您的第一個(gè)PHP腳本:實(shí)用介紹 您的第一個(gè)PHP腳本:實(shí)用介紹 Jul 16, 2025 am 03:42 AM

如何開始編寫第一個(gè)PHP腳本?首先設(shè)置本地開發(fā)環(huán)境,安裝XAMPP/MAMP/LAMP,使用文本編輯器,了解服務(wù)器運(yùn)行原理。其次,創(chuàng)建一個(gè)名為hello.php的文件,輸入基本代碼并運(yùn)行測試。第三,學(xué)習(xí)混合使用PHP與HTML以實(shí)現(xiàn)動態(tài)內(nèi)容輸出。最后,注意常見錯(cuò)誤如缺少分號、引用問題及文件擴(kuò)展名錯(cuò)誤,并開啟錯(cuò)誤報(bào)告以便調(diào)試。

您如何處理PHP中的文件操作(閱讀/寫作)? 您如何處理PHP中的文件操作(閱讀/寫作)? Jul 16, 2025 am 03:48 AM

tohandlefileoperationsinphp,useApprepreprunctions andModes.1.toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline by line-line-processing.2.towriteToafile,usefile_put_cte_contents(usefile_contents)(

See all articles