導航:首頁 > 編程語言 > php判斷輸入的驗證碼

php判斷輸入的驗證碼

發布時間:2024-08-26 13:05:11

『壹』 phpcms 如何判斷驗證碼輸入正確

驗證碼生成後對應的數值存貯在session中,可安裝如下代碼進行判斷:

$this->_session_start();//開啟sesseion
......
//判斷驗證碼
$code=isset($_POST['code'])&&trim($_POST['code'])?trim($_POST['code']):showmessage(L('input_code'),HTTP_REFERER);
if($_SESSION['code']!=strtolower($code)){
showmessage(L('code_error'),HTTP_REFERER);
}

『貳』 用PHP、JS寫判斷驗證碼是否正確,不要alert彈出框,我要的是在輸入之後顯示是否正確。

注冊按鈕綁定click 事件 事件開頭判斷 Checkvar();

如果是FORM 要在 聲明onsubmit="Checkvar();"

functionCheckvar(){

varvarcode=$("#vc");//這里獲取輸入的注冊碼
vartipsmsg=$("#msg")//提示框對象
$.ajax({
url:"checkcode.php?code="+varcode+"&",
async:false,//關閉非同步

success:function(data){用回調函數檢查伺服器返回的結果
if(data=="0"){未通過
tipsmsg.html('驗證碼錯誤');
returnfalse;
}else{//通過
tipsmsg.html('成功');
returntrue;
}

}
});
}

checkcode.php
<?
session_start();

if($code==$_SESSION["code"]){

echo"1";
}else{
echo"0";
}
?>

『叄』 php中用戶輸入的驗證碼怎樣用javascript 代碼進行判斷 是否輸入正確

驗證碼一般都是在伺服器隨機產生,在html頁面用ajax獲取驗證碼來和用戶輸入的驗證碼進行比較
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function doit()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("get","auth_code.php",true);
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200 || xmlHttp.status==0)
{
checkAuthCodeInput(xmlHttp.responseText);
}
}
}
function checkAuthCodeInput(authcode)
{
if(document.getElementById("自定義").value==auth)
{
return true;
}
return false;
}
</script>
<img src="auth_code.php" id="img_auth_code"/>
<a href="document.getElementById('img_auth_code').src='auth_code.php?code='+Math.random();">看不清,再換一張</a>

//該頁面用於隨機獲取驗證碼rand_auth_code.php
<?php
function get_auth_code()
{
for($i=0;$i<5;$i++)
{
$_GLOBALS['rand_str'].=strtoupper(dechex(rand(0,15)));
rand_str_width+=imagefontwidth($i);
}
}
echo $_GLOBALS['rand_str'];
?>

<?php
include_once("rand_auth_code.php");//導入產生驗證碼的頁面
$img_width=100;
$img_height=25;
$img=imagecreatetruecolor($img_width,$img_height);

$img_bg_color=imagecolorallocate($img,0,0,0);

imagefill($img,0,0,$img_bg_color);

$img_font_color=imagecolorallocate($img,225,225,225);

get_auth_code();//調用方法,產生隨機驗證碼

$img_font_x=$img_width/2 - $rand_str_width/2;
$img_font_y=($img_height-imagefontwidth(5))/2;

imagestring($img,5,$img_font_x,$img_font_y,$_GLOBALS[rand_str],$img_font_color);

header("Content-Type:image/jpeg");

imagejpeg($img);

imagedestroy($img);
unset($_GLOBALS['rand_str']);
?>

不知是否符合你的要求

『肆』 php 怎麼獲取驗證碼的值

$_SESSION["vcode"] = $vcode;
驗證碼的值就在 $_SESSION["vcode"] 裡面。

閱讀全文

與php判斷輸入的驗證碼相關的資料

熱點內容
64位java內存 瀏覽:418
女程序員學習方法 瀏覽:383
工程數學線性代數pdf 瀏覽:681
提升程序員技術檔次的書 瀏覽:691
python詞雲圖txt格式 瀏覽:968
韓國料理pdf 瀏覽:227
什麼app就能知道自己的臉型 瀏覽:383
准了app月卡可以看什麼 瀏覽:140
雲伺服器開機要開30秒 瀏覽:646
php數組傳遞給js 瀏覽:640
在世紀的轉折點上pdf 瀏覽:857
變頻製冷壓縮機性能實驗 瀏覽:575
印刷哪個app好 瀏覽:367
安卓手機如何查看連接過的wifi密碼 瀏覽:461
chrpythonord 瀏覽:353
android切片 瀏覽:231
前端js調用php 瀏覽:591
文件夾res是什麼 瀏覽:488
linuxput命令 瀏覽:932
智能仿生演算法模擬退火 瀏覽:903