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

首頁 後端開發(fā) php教程 一個php驗證碼產生類別代碼

一個php驗證碼產生類別代碼

Jul 25, 2016 am 08:43 AM

複製程式碼
  1. class ValidationCode
  2. {
  3. // 屬性
  4. private $width;
  5. private $priight; ;
  6. 私人$image;
  7. 私人$disturbColorNum; //幹擾元素數量
  8. private $checkCode;
  9. function __construct($width=80,$height=20,$codeNum=4)
  10. {
  11. $this->width=$width;
  12. $this->height=$height;
  13. $this->codeNum=$codeNum;
  14. $number=floor($width*$height/15);
  15. if($number> ; 240-$codeNum)
  16. {
  17. $this->disturbColorNum=240-$codeNum;
  18. }else
  19. {
  20. $this->disturbColorNum=$number;
  21. }
  22. $this->checkCode=$this->createCheckcode();
  23. }
  24. function getCheckCode()
  25. {
  26. return $this->checkCode;
  27. }
  28. private function createImage (){
  29. $this->image=imagecreatetruecolor($this->寬度,$this->高度);
  30. $backcolor=imagecolorallocate($this->image ,rand(225,255),rand(225,255) ,rand(255,255));
  31. imagefill($this->image,0,0,$backcolor);
  32. $border=imagecolorallocate($this->; image,0,0,0);
  33. imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$border);
  34. }
  35. 原生函數setDisturbColor(){
  36. for ($i=0;$idisturbColorNum;$i ){
  37. $color=imagecolorallocate($this->image,rand (0,255),rand(0,255),rand(0,255));
  38. imagesetpixel($this->image,rand(1,$this->width-2),rand(1,$this->image) height-2),$color);
  39. }
  40. for ($i=0;$i {
  41. $color=imagecolorallocate($this->image, rand(0,255),rand(0,255),rand(0,255));
  42. imagearc($this->影像,rand(-10,$this->寬度),rand(-10,$this->;高度),rand(30,300),rand(20,300),55,44,$color );
  43. }
  44. }
  45. 牛皮函數outputText($fontFace=""){
  46. for($ i=0;$icodeNum;$i )
  47. {
  48. $fontcolor=imagecolorallocate($this->image,rand(0,128),rand(0,128),rand(0,128) );
  49. if($fontFace=="")
  50. {
  51. $ fontsize=rand(3,5);
  52. $x=floor($this->width/$this-> ;codeNum)*$i 5;
  53. $y=rand(0,$this->height -15);
  54. imagechar($this->圖片,$fontsize,$x,$y,$這->checkCode{$i},$fontcolor);
  55. }
  56. else
  57. {
  58. $fontsize=rand(12,16);
  59. $x=floor(($this ->width-8)/$this->codeNum)*$i 8;
  60. $y=rand( $fontsize,$this->height-8);
  61. imagettftext($this-> ;圖片,$fontsize,rand(-45,45),$x,$y,$fontcolor,$fontFace,$this- >checkCode{$i});
  62. }
  63. }
  64. }
  65. private function createCheckCode(){
  66. $code="23456789abcdefghijkm(){
  67. $code="23456789abcdefghijkm for($i=0;$icodeNum ;$i )
  68. {
  69. $char=$code{rand(0,strlen($code)-1)};
  70. $str.=$char;
  71. }
  72. 回傳$ str;
  73. }
  74. 原生函數outputImage()
  75. {
  76. if(imagetypes()&IMG_GIF)
  77. {
  78. header("Content-Type:image/gif");
  79. imagepng($this->image);
  80. }else if(imagetypes()&IMG_JPG)
  81. {
  82. header( "Content-Type:image/jpeg");
  83. imagepng($this ->image);
  84. }else if(imagetypes()&IMG_PNG)
  85. {
  86. header("Content-Type:image /png");
  87. imagepng($this->image) ;
  88. }else if(imagetypes()&IMG_WBMP){
  89. header("Content-Type:image/vnd.wap.wbmp");
  90. imagepng($this->image);
  91. }else
  92. {
  93. die("PHP不支援圖片驗證碼");
  94. }
  95. }
  96. //透過此方法向瀏覽器輸出圖像
  97. function showImage($fontFace ="")
  98. {
  99. //圖像背景建立
  100. $this->createImage();
  101. //設定乾預元素
  102. $this->setDisturbColor();
  103. // 向圖像中隨機畫出文字
  104. $this->outputText($fontFace);
  105. // 圖像輸出
  106. $this->輸出影像();
  107. }
  108. function __destruct()
  109. {
  110. imagedestroy($this->image);
  111. }
  112. }
  113. function checklogin(){
  114. if(empty( _POST['name']))
  115. die( '使用者名稱不能為空');
  116. if(empty($_POST['password']))
  117. die("密碼不能為空") ;
  118. if($_SESSION['code']!=$_POST['vertify'])
  119. die("驗證碼輸入不正確".$_SESSION['code']);
  120. $username=$_POST['name'];
  121. $password=md5($_POST['password']);
  122. //檢查是否存在
  123. conndb($username,$password);
  124. }
  125. function conndb($name="",$ps=""){
  126. $conn=mysql_connect('localhost','root','123456');
  127. if(!$ conn) die("資料庫連線失敗".mysql_error());
  128. mysql_select_db('5kan',$conn) or die('選擇資料庫失敗'.mysql_error());
  129. mysql_set_charset('utf8', $conn);
  130. $sql="select id from k_user where username='{$name}' and password='{$ps}'";
  131. $result=mysql_query($sql) or die(" SQL語句錯誤".mysql_error());
  132. if(mysql_num_rows($result)>0) die("登入成功");
  133. else die("使用者名稱或密碼錯誤");
  134. mysql_close ($conn);
  135. }
  136. session_start();
  137. if(!isset($_POST['randnum']))
  138. {
  139. $code=new ValidationCode(120,20, 4);
  140. $code->showImage("comicbd.ttf"); //顯示在頁面
  141. $_SESSION['code']=$code->getCheckCode();//儲存在伺服器中
  142. }
  143. else
  144. {
  145. checklogin();
  146. }
  147. ?>
複製程式碼

複製程式碼
複製程式碼


複製程式碼複製程式碼複製程式碼複製碼 驗證碼, php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發(fā)現涉嫌抄襲或侵權的內容,請聯(lián)絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

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

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

對基於PHP的API進行版本控制的最佳實踐是什麼? 對基於PHP的API進行版本控制的最佳實踐是什麼? Jun 14, 2025 am 12:27 AM

基於toversionaphp,useUrl deuseUrl specteringforclarityAndEsofRouting,單獨的codetoavoidConflicts,dremecateOldVersionswithClearCommunication,andConsiderCustomHeadeSerlySerallyWhennEnncelsy.startbyplacingtheversionIntheUrl(E.G.,epi/api/v

如何在PHP中實施身份驗證和授權? 如何在PHP中實施身份驗證和授權? Jun 20, 2025 am 01:03 AM

tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.

PHP中的程序和麵向對象的編程範例之間有什麼區(qū)別? PHP中的程序和麵向對象的編程範例之間有什麼區(qū)別? Jun 14, 2025 am 12:25 AM

procemal and object-tiriendedprogromming(oop)inphpdiffersimplessintustructure,可重複使用性和datahandling.1.procedural-Progrogursmingusesfunctimesfunctionsormanized sequalized sequalized sequiential,poiperforsmallscripts.2.OpporganizesCodeOrganizescodeOdeIntsocloceSandObjects,ModelingReal-Worlden-Worlden

PHP中有哪些弱參考(弱圖),何時有用? PHP中有哪些弱參考(弱圖),何時有用? Jun 14, 2025 am 12:25 AM

PHPdoesnothaveabuilt-inWeakMapbutoffersWeakReferenceforsimilarfunctionality.1.WeakReferenceallowsholdingreferenceswithoutpreventinggarbagecollection.2.Itisusefulforcaching,eventlisteners,andmetadatawithoutaffectingobjectlifecycles.3.YoucansimulateaWe

如何在PHP中安全地處理文件上傳? 如何在PHP中安全地處理文件上傳? Jun 19, 2025 am 01:05 AM

要安全處理PHP中的文件上傳,核心在於驗證文件類型、重命名文件並限制權限。 1.使用finfo_file()檢查真實MIME類型,僅允許特定類型如image/jpeg;2.用uniqid()生成隨機文件名,存儲至非Web根目錄;3.通過php.ini和HTML表單限製文件大小,設置目錄權限為0755;4.使用ClamAV掃描惡意軟件,增強安全性。這些步驟有效防止安全漏洞,確保文件上傳過程安全可靠。

PHP中==(鬆散比較)和===(嚴格的比較)之間有什麼區(qū)別? PHP中==(鬆散比較)和===(嚴格的比較)之間有什麼區(qū)別? Jun 19, 2025 am 01:07 AM

在PHP中,==與===的主要區(qū)別在於類型檢查的嚴格程度。 ==在比較前會進行類型轉換,例如5=="5"返回true,而===要求值和類型都相同才會返回true,例如5==="5"返回false。使用場景上,===更安全應優(yōu)先使用,==僅在需要類型轉換時使用。

如何與PHP的NOSQL數據庫(例如MongoDB,Redis)進行交互? 如何與PHP的NOSQL數據庫(例如MongoDB,Redis)進行交互? Jun 19, 2025 am 01:07 AM

是的,PHP可以通過特定擴展或庫與MongoDB和Redis等NoSQL數據庫交互。首先,使用MongoDBPHP驅動(通過PECL或Composer安裝)創(chuàng)建客戶端實例並操作數據庫及集合,支持插入、查詢、聚合等操作;其次,使用Predis庫或phpredis擴展連接Redis,執(zhí)行鍵值設置與獲取,推薦phpredis用於高性能場景,Predis則便於快速部署;兩者均適用於生產環(huán)境且文檔完善。

如何在PHP( - , *, /,%)中執(zhí)行算術操作? 如何在PHP( - , *, /,%)中執(zhí)行算術操作? Jun 19, 2025 pm 05:13 PM

PHP中使用基本數學運算的方法如下:1.加法用 號,支持整數和浮點數,也可用於變量,字符串數字會自動轉換但不推薦依賴;2.減法用-號,變量同理,類型轉換同樣適用;3.乘法用*號,適用於數字及類似字符串;4.除法用/號,需避免除以零,並註意結果可能是浮點數;5.取模用%號,可用於判斷奇偶數,處理負數時餘數符號與被除數一致。正確使用這些運算符的關鍵在於確保數據類型清晰並處理好邊界情況。

See all articles