導航:首頁 > 編程語言 > php點擊更換驗證碼

php點擊更換驗證碼

發布時間:2022-06-09 18:36:41

A. php 驗證碼類,怎麼改變驗證碼形狀

直接上代碼:
復制代碼 代碼如下:
//驗證碼類
class ValidateCode {
private $charset = '';//隨機因子private $code;//驗證碼
private $codelen = 4;//驗證碼長度
private $width = 130;//寬度
private $height = 50;//高度
private $img;//圖形資源句柄
private $font;//指定的字體
private $fontsize = 20;//指定字體大小
private $fontcolor;//指定字體顏色
//構造方法初始化
public function __construct() {
$this->font = dirname(__FILE__).'/font/elephant.ttf';//注意字體路徑要寫對,否則顯示不了圖片}
//生成隨機碼
private function createCode() {
$_len = strlen($this->charset)-1;
for ($i=0;$i<$this->codelen;$i++) {
$this->code .= $this->charset[mt_rand(0,$_len)];}
}
//生成背景
private function createBg() {
$this->img = imagecreatetruecolor($this->width, $this->height);$color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);}
//生成文字
private function createFont() {
$_x = $this->width / $this->codelen;
for ($i=0;$i<$this->codelen;$i++) {
$this->fontcolor = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height / 1.4,$this->fontcolor,$this->font,$this->code[$i]);}
}
//生成線條、雪花
private function createLine() {
//線條
for ($i=0;$i<6;$i++) {
$color = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);}
//雪花
for ($i=0;$i<100;$i++) {
$color = imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);}
}
//輸出
private function outPut() {
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//對外生成
public function doimg() {
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//獲取驗證碼
public function getCode() {
return strtolower($this->code);
}
}
輸出實例:
使用方法:
1、先把驗證碼類保存為一個名為 ValidateCode.class.php 的文件;2、新建一個名為 captcha.php 的文件進行調用該類;captcha.php
復制代碼 代碼如下:
session_start();
require './ValidateCode.class.php'; //先把類包含進來,實際路徑根據實際情況進行修改。
$_vc = new ValidateCode(); //實例化一個對象$_vc->doimg();
$_SESSION['authnum_session'] = $_vc->getCode();//驗證碼保存到SESSION中3、引用到頁面中,代碼如下:
復制代碼 代碼如下:
<img title="點擊刷新" src="./captcha.php" align="absbottom" onclick="this.src='captcha.php?'+Math.random();"></img>
4、一個完整的驗證頁面,代碼如下:
復制代碼 代碼如下:
<?php
session_start();
//在頁首先要開啟session,
//error_reporting(2047);
session_destroy();
//將session去掉,以每次都能取新的session值;//用seesion 效果不錯,也很方便
?>
<html>
<head>
<title>session 圖片驗證實例</title>
<style type="text/css">
#login p{
margin-top: 15px;
line-height: 20px;
font-size: 14px;
font-weight: bold;
}
#login img{
cursor:pointer;
}
form{
margin-left:20px;
}
</style>
</head>
<body>
<form id="login" action="" method="post">
<p>此例為session驗證實例</p>
<p>
<span>驗證碼:</span>
<input type="text" name="validate" value="" size=10>
<img title="點擊刷新" src="./captcha.php" align="absbottom" onclick="this.src='captcha.php?'+Math.random();"></img>
</p>
<p>
<input type="submit">
</p>
</form>
<?php
//列印上一個session;
//echo "上一個session:<b>".$_SESSION["authnum_session"]."</b><br>";$validate="";
if(isset($_POST["validate"])){
$validate=$_POST["validate"];
echo "您剛才輸入的是:".$_POST["validate"]."<br>狀態:";if($validate!=$_SESSION["authnum_session"]){//判斷session值與用戶輸入的驗證碼是否一致;echo "<font color=red>輸入有誤</font>";
}else{
echo "<font color=green>通過驗證</font>";}
}
?>

B. php中如何刷新驗證碼

我做的一個簡單的登錄界面有刷新驗證碼還有注冊功能 希望對LZ有幫助
這個是登錄界面 land.php
<?php
@include_once('global.php');
session_start();
$user = $_POST['username'];
$sql = sprintf("select * from `p_admin` where `username` = '%s'",$user);
//echo $sql;
$query = $db->query($sql);//調用golbal裡面的$db類
$fetch = $db->fetch_array($query);
if($_POST['sccode']==$_SESSION['rand']){
$state = $fetch ? md5($_POST['password'].$extra)==$fetch['password']:FALSE;//是否登錄成功 如果失敗了返回為空echo $state沒有結果
if(!$state)
echo"<script language=javascript>alert('用戶名或密碼錯誤');</script>";

else {
$_SESSION['id'] = $fetch['m_id'];
$_SESSION['shell'] = md5($fetch['username'].$fetch['password']);
$_SESSION['ontime'] = time();
//echo $_SESSION['id']."<br>";
//echo $_SESSION['shell'];
$action = new action();
$action ->get_show_msg('admin/admin_main.php', $show = '操作已成功!');
}
}else
echo "<script language=javascript>alert('驗證碼錯誤');</script>";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>

<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>用戶登錄</title>
<link href="style/global.css" rel="stylesheet" type="text/css">
<link href="style/link.css" rel="stylesheet" type="text/css">
<link href="style/layoutid.css" rel="stylesheet" type="text/css">
<script language="javascript">
function chform (obj) {
if (obj.username.value == "") {
alert("請輸入用戶名!");
obj.username.focus();
return false;
}
if (obj.password.value == "") {
alert("請輸入密碼!");
obj.password.focus();
return false;
}
if (obj.sccode.value == "") {
alert("請輸入驗證碼!");
obj.sccode.focus();
return false;
}
return true;
}
function RefreshImage(id)
{
document.getElementById(id).src ='Confirm.php?'+Math.random(1);
}
</script>
</head><body>
<!--用戶登錄開始-->
<div class="login">
<form id="form1" name="form1" method="post" action="" onsubmit="return chform(this)">
<ul>
<li class="loginbtbj fright" style="background-image: url("images/hydl.gif");"><a title="" href="javascript:%20close();"><img src="images/close.gif" alt="關閉" align="right" border="0" height="18" width="18"></a></li>
<li class="fyellowxx fcenter">
.............................................................................................................
</li>
<li class="padleft43">
用戶名:<input name="username" size="15" style="width: 150px;" type="text">
</li>
<li class="padleft43">
密碼:<input name="password" size="15" style="width: 150px;" type="password">
</li>
<li class="padleft43">
驗證碼:<input name="sccode" size="6" style="width: 50px;" type="text"><img id="re_confirm" onclick="RefreshImage('re_confirm')" src="Confirm.php">
<a title="看不清?" href="#" onclick="RefreshImage('re_confirm')">看不清?</a> <a href=register.php >注冊</a>

</li>
<li class="fyellowxx fcenter">
.............................................................................................................
<br>
<input name="Submit" src="images/dl.gif" style="border: 0pt none; width: 80px; height: 31px;" type="image">
</li>
</ul>
</form>
</div>
<!--用戶登錄結束-->
</body></html>
這個是驗證碼的程序 confirm.php 圖片什麼的代碼我就不穿了 LZ可以借鑒下 有一點需要注意 就是這個confirm文件裡面不能報錯 我在這卡了很久
因為header這個之前不能輸出文本 所以如果報錯 就會無法顯示驗證碼
<?php
session_start();
$random='';
for($i=1;$i<5;$i++){
$random .= dechex(rand(1,15));}
$_SESSION['rand']=$random;
$im = imagecreatetruecolor(40,20);
$bg = imagecolorallocate($im,0,0,0);
$te = imagecolorallocate($im,255,255,255);
imagestring($im,rand(1,6),rand(1,6),rand(1,6),$random,$te);
header("Content-type: image/jpeg");
imagejpeg($im);
?>

C. phpweb 網站進入後台的時候:請輸入和圖片上顯示一致的驗證碼,點擊驗證碼圖片可更換一張。可我沒輸錯。

終結版:
1時間,時區設置是否正確。
2清空瀏覽器緩存。
3你是否通過路由器上網,請去掉路由器試試,如果可以,請升級路由器固件或者更換路由器。
我估計你那個是第三條了

D. php源碼手機驗證更換成郵箱驗證

這個不是幾行代碼就能給出結果的事。
1:將原代碼里的手機驗證去掉。
2:添加phpmailer,並用一個自己的郵箱作為發信箱
3:用戶在注冊時,要求其填寫郵箱
4:用戶提交注冊信息,POST處理完成後,發送一封郵件到其填寫的注冊郵箱

驗證有兩種辦法:
1:發送一個系統生成的字元串(一般3-6位數字即可),用戶在郵箱中查看到郵件後,進行復制粘貼激活
2:發送一個特定的URL到郵箱,用戶點擊該URL,即可完成激活

E. phpweb 網站進入後台的時候:請輸入和圖片上顯示一致的驗證碼,點擊驗證碼圖片可更換一張。可我沒輸錯

大哥 我可以很明確的告訴你 如果一個問題在網路討論的很少 這個問題除非特別特別難 不過大多應該基本不是問題 可能會難住你一陣子 但最後你解決後你才會發現這個問題你多麼的簡單 自己是多麼的愚蠢 思路想錯了 呵呵 所以你這個問題很容易找到答案 你整了一堆沒用的 一句話本地網路的原因 網路不給力 我很懷疑你的驗證碼是不是沒用同步 你每次輸入的驗證碼其實已經變了 建議你在拼音的時候輸入 別用搜狗打字母然後按enter輸驗證碼 這樣驗證碼會跳一次 會改變 如果你網路不行沒有刷新你就看不到 自然會錯 如果你用搜狗輸入法 你先點擊一下shift然後輸入驗證碼 輸入後你用滑鼠點擊登錄 別按到enter鍵了 不然驗證碼會跳的 別瞎折騰了 問題沒那麼嚴重 不要輕易裝系統 電腦裡面裝的軟體重裝一次不容易

F. php文件如何通過點擊一個鏈接刷新驗證碼

差不多是一樣的的道理,只是更新的是圖片的src,獲取對象的時候改一下就行了。

jquery代碼:

<aherf="#"onclick="$('#vdimgck').attr('src','code.php?'+Math.random())">換一張</a>

G. php點擊刷新驗證碼

第二個 onclick 事件寫的不對。真確寫法如下

<ahref="#"onclick="document.getElementById('code').src='code.php?tm='+Math.random()">看不清楚,刷新</a>

你貌似沒搞清楚 js 裡面的this 到底是什麼,所簡單點 this 寫在哪個標簽里,指的就是那個標簽。

H. php中驗證碼的那個「換一張」的鏈接怎麼寫

基本思路就是,寫個Ajax,當點擊「換一張」時,請求一個生成驗證碼的PHP程序文件。當請求成功時,用Javascript代碼把驗證碼替換誠心的就可以了。

I. 用php程序的jquery控制點擊更換驗證碼瀏覽器不兼容問題

1. 換驗證碼的時候,驗證碼生成地址後面國加一個隨機數
2. 如果是a標簽為點擊的話,href設為#
eg.
<img src="vimg.php" id="vpic" width="150" height="50" />
<a href="#" onclick="reload()">看不清楚? 換一個</a>
<script type="text/javascript">
function reload(){
var cpt = document.getElementById('vpic');
var src = cpt.src;
cpt.src = src+'?'+Math.random();
}
</script>

J. PHP驗證碼 實現點擊刷新

隨機產生的驗證碼放在一個文件1中
在另一個文件中引用文件1
<img src="code.php" onClick="this.src='code.php?nocache='+Math.random()" style="cursor:hand" alt="點擊換一張"/>

實現點擊圖片自動刷新圖片

閱讀全文

與php點擊更換驗證碼相關的資料

熱點內容
魯班鎖解壓嗎 瀏覽:395
打包發送文件如何加密 瀏覽:213
centos解壓縮zip 瀏覽:387
我的世界怎麼用命令風塊取消指令 瀏覽:1000
安卓軟體請求超時怎麼辦 瀏覽:476
androidapp調用另一個app 瀏覽:621
數控銑床法蘭克子程序編程 瀏覽:173
linux打包命令targz 瀏覽:996
抖音app是哪個 瀏覽:407
蘋果app怎麼上架 瀏覽:255
NA伺服器地址 瀏覽:427
我的世界如何初始化伺服器 瀏覽:97
哪個手機app天氣預報最准 瀏覽:752
怎樣把視頻壓縮至25m 瀏覽:570
vivox27文件夾怎麼改變 瀏覽:727
新手玩狼人殺用什麼app 瀏覽:615
pdf在線查看 瀏覽:954
安卓tv90如何關閉後台 瀏覽:683
php讀取word亂碼 瀏覽:755
minicom源碼 瀏覽:1002