導航:首頁 > 編程語言 > 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判斷輸入的驗證碼相關的資料

熱點內容
android打譜 瀏覽:400
密室大逃脫在什麼app裡面是免費的 瀏覽:982
ecs雲伺服器ftp 瀏覽:626
郵緒生活app什麼意思 瀏覽:469
如何知曉伺服器是否更新完成 瀏覽:949
北票女程序員 瀏覽:463
戰地2槍械解壓 瀏覽:41
pdf復選框 瀏覽:343
linux用戶監控 瀏覽:35
化妝教程編譯 瀏覽:133
python分組鍵的形式 瀏覽:721
佛教造像pdf 瀏覽:664
醫療不良事件上報系統源碼 瀏覽:754
手機雲視頻加密怎麼關 瀏覽:74
北京文件夾加密多少錢 瀏覽:671
什麼是車鑒定app 瀏覽:67
戰地一私人伺服器怎麼買 瀏覽:497
陳天程序員 瀏覽:833
編譯原理如何運用到編程中 瀏覽:18
linux選擇資料庫 瀏覽:377