PHP ???? ??(GD ??????? ???? ??)
Jul 25, 2016 am 08:59 AM
為大家介紹一個php使用GD庫生成驗證碼的例子,有需要的朋友,可以參考下。
通過GD生成PNG圖片,并把$randval隨機(jī)數(shù)字賦給$_SESSION['login_check_num'],在通過用戶輸入的$_POST進(jìn)行比較,來判斷是否正確。 注意:如果服務(wù)器未開啟GD庫支持,需要修改php.ini文件,使php支持GD庫。(專題推薦:php驗證碼大全) 代碼如下: <?php //調(diào)用生成驗證碼圖片 //by http://bbs.it-home.org if($_GET["action"]=="verifycode") { rand_create(); } //生成驗證碼圖片 function rand_create() { //通知瀏覽器將要輸出PNG圖片 Header("Content-type: image/PNG"); //準(zhǔn)備好隨機(jī)數(shù)發(fā)生器種子 srand((double)microtime()*1000000); //準(zhǔn)備圖片的相關(guān)參數(shù) $im = imagecreate(62,20); $black = ImageColorAllocate($im, 0,0,0); //RGB黑色標(biāo)識符 $white = ImageColorAllocate($im, 255,255,255); //RGB白色標(biāo)識符 $gray = ImageColorAllocate($im, 200,200,200); //RGB灰色標(biāo)識符 //開始作圖 imagefill($im,0,0,$gray); while(($randval=rand()%100000)<10000);{ $_SESSION["login_check_num"] = $randval; //將四位整數(shù)驗證碼繪入圖片 imagestring($im, 5, 10, 3, $randval, $black); } //加入干擾象素 for($i=0;$i<200;$i++){ $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); } //輸出驗證圖片 ImagePNG($im); //銷毀圖像標(biāo)識符 ImageDestroy($im); } //檢驗驗證碼 function rand_check() { if($_POST["reg_rand"] == $_SESSION["login_check_num"]){ return true; } else{ exit("驗證碼輸入錯誤"); } } ?> |

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2
