php驗證碼不變的解決方法:1、使用“javascript:ckimg();”方法實現更換一張驗證碼;2、透過“οnclick="this.src='...”方法實作點擊換圖片即可。
本文操作環境:Windows7系統、PHP7.1版、DELL G3電腦
php 驗證碼不變怎麼辦?
php驗證碼無刷新改變(更換)
#test.php
<script> function ckimg(){ document.getElementById('img').src="validateCode2.php?"+new Date().getTime(); } </script> <meta> <title></title> <!--第一种方法--> <a><img src="/static/imghwm/default1.png" data-src="validateCode2.php" class="lazy" alt="php 驗證碼不變怎麼辦" ></a> <a>看不清,请换一张</a> <!--第二种方法--> <img src="/static/imghwm/default1.png" data-src="validateCode2.php" class="lazy" alt="php 驗證碼不變怎麼辦" >
生產驗證碼的類,包含了一些驗證碼產生的參數,如:大小,顏色,顯示驗證碼的符號類型
validateCode2.php
<?php session_start(); class Authnum { //图片对象、宽度、高度、验证码长度 private $im; private $im_width; private $im_height; private $len; //随机字符串、y轴坐标值、随机颜色 private $randnum; private $y; private $randcolor; //背景色的红绿蓝,默认是浅灰色 public $red=238; public $green=238; public $blue=238; /** * 可选设置:验证码类型、干扰点、干扰线、Y轴随机 * 设为 false 表示不启用 **/ //默认是大小写数字混合型,1 2 3 分别表示 小写、大写、数字型 public $ext_num_type=''; public $ext_pixel = false; //干扰点 public $ext_line = false; //干扰线 public $ext_rand_y= true; //Y轴随机 function __construct ($len=4,$im_width='',$im_height=25) { // 验证码长度、图片宽度、高度是实例化类时必需的数据 $this->len = $len; $im_width = $len * 15; $this->im_width = $im_width; $this->im_height= $im_height; $this->im = imagecreate($im_width,$im_height); } // 设置图片背景颜色,默认是浅灰色背景 function set_bgcolor () { imagecolorallocate($this->im,$this->red,$this->green,$this->blue); } // 获得任意位数的随机码 function get_randnum () { $an1 = 'abcdefghijklmnopqrstuvwxyz'; $an2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $an3 = '0123456789'; if ($this->ext_num_type == '') $str = $an1.$an2.$an3; if ($this->ext_num_type == 1) $str = $an1; if ($this->ext_num_type == 2) $str = $an2; if ($this->ext_num_type == 3) $str = $an3; for ($i = 0; $i len; $i++) { $start = rand(1,strlen($str) - 1); $randnum .= substr($str,$start,1); } $this->randnum = $randnum; $_SESSION[an] = $this->randnum; } // 获得验证码图片Y轴 function get_y () { if ($this->ext_rand_y) $this->y = rand(5, $this->im_height/5); else $this->y = $this->im_height / 4 ; } // 获得随机色 function get_randcolor () { $this->randcolor = imagecolorallocate($this->im,rand(0,100),rand(0,150),rand(0,200)); } // 添加干扰点 function set_ext_pixel () { if ($this->ext_pixel) { for($i = 0; $i get_randcolor(); imagesetpixel($this->im, rand()%100, rand()%100, $this->randcolor); } } } // 添加干扰线 function set_ext_line () { if ($this->ext_line) { for($j = 0; $j im_width); $rand_y = rand(2, $this->im_height); $rand_x2 = rand(2, $this->im_width); $rand_y2 = rand(2, $this->im_height); $this->get_randcolor(); imageline($this->im, $rand_x, $rand_y, $rand_x2, $rand_y2, $this->randcolor); } } } /**创建验证码图像: * 建立画布(__construct函数) * 设置画布背景($this->set_bgcolor();) * 获取随机字符串($this->get_randnum ();) * 文字写到图片上(imagestring函数) * 添加干扰点/线($this->set_ext_line(); $this->set_ext_pixel();) * 输出图片 **/ function create () { $this->set_bgcolor(); $this->get_randnum (); for($i = 0; $i len; $i++){ $font = rand(4,6); $x = $i/$this->len * $this->im_width + rand(1, $this->len); $this->get_y(); $this->get_randcolor(); imagestring($this->im, $font, $x, $this->y, substr($this->randnum, $i ,1), $this->randcolor); } $this->set_ext_line(); $this->set_ext_pixel(); header("content-type:image/png"); imagepng($this->im); imagedestroy($this->im); //释放图像资源 } }//end class /**使用验证码类的方法: * $an = new Authnum(验证码长度,图片宽度,图片高度); * 实例化时不带参数则默认是四位的60*25尺寸的常规验证码图片 * 表单页面检测验证码的方法,对比 $_SESSION[an] 是否等于 $_POST[验证码文本框ID] * 可选配置: * 1.验证码类型:$an->ext_num_type=1; 值为1是小写类型,2是大写类型,3是数字类型 * 2.干扰点:$an->ext_pixel = false; 值为false表示不添加干扰点 * 3.干扰线:$an->ext_line = false; 值为false表示不添加干扰线 * 4.Y轴随机:$an->ext_rand_y = false; 值为false表示不支持图片Y轴随机 * 5.图片背景:改变 $red $green $blue 三个成员变量的值即可 **/ $an = new Authnum(); $an->ext_num_type=''; $an->ext_pixel = true; //干扰点 $an->ext_line = false; //干扰线 $an->ext_rand_y= true; //Y轴随机 $an->green = 238; $an->create(); ?>
推薦學習:《PHP影片教學》
#以上是php 驗證碼不變怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文比較了酸和基本數據庫模型,詳細介紹了它們的特徵和適當的用例。酸優先確定數據完整性和一致性,適合財務和電子商務應用程序,而基礎則側重於可用性和

本文討論了確保PHP文件上傳的確保,以防止諸如代碼注入之類的漏洞。它專注於文件類型驗證,安全存儲和錯誤處理以增強應用程序安全性。

本文討論了在PHP中實施API速率限制的策略,包括諸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之類的庫。它還涵蓋監視,動態調整速率限制和手

本文討論了使用password_hash和pyspasswify在PHP中使用密碼的好處。主要論點是,這些功能通過自動鹽,強大的哈希算法和SECH來增強密碼保護

本文討論了OWASP在PHP和緩解策略中的十大漏洞。關鍵問題包括注射,驗證損壞和XSS,並提供用於監視和保護PHP應用程序的推薦工具。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

WebStorm Mac版
好用的JavaScript開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器