怎么用AJAX來判斷dedecms用戶是否登錄呢


JS代碼:
Copy code
<script language="javascript" src="{dede:global name='cfg_cmspath'/}/include/dedeajax2.js"></script>
<script language="javascript">
function CheckUser(){
var taget_obj = document.getElementById('_userboxform');
myajax = new DedeAjax(taget_obj,false,false,"","","");
myajax.SendGet2("{dede:global name="cfg_memberurl"/}/userboxsta.php");
DedeXHTTP = null;
}
</script>
然后我們修改下內容頁部分的代碼
找到:
<div class="userbox">
<dl>
<dd class="mtop">
<strong>用戶名:</strong><input name="username" class="username" type="text" maxlength="20" />
<strong>密碼:</strong><input name="pwd" class="password" type="password" maxlength="20" />
</dd>
將其修改為
<div class="userbox">
<dl>
<dd class="mtop"> <span id="_userboxform">
<strong>用戶名:</strong><input name="username" class="username" type="text" maxlength="20" />
<strong>密碼:</strong><input name="pwd" class="password" type="password" maxlength="20" /> </span> 
</dd>
即加上<span id="_userboxform">,用於判斷用戶是否已經登錄。
下面我們來寫一�php文件,用戶傳送數據,將其保存為/member/userboxsta.php,其代碼如下:
Copy code
<?php 
header("Pragma:no-cache\r\n");
header("Cache-Control:no-cache\r\n");
header("Expires:0\r\n");
header("Content-Type: text/html; charset=gb2312");
//系統設置為維護狀態可訪問
$cfg_IsCanView = true;
require_once(dirname(__FILE__)."/../include/inc_memberlogin.php");
$cfg_ml = new MemberLogin(); 
if(empty($cfg_ml->M_ID)){ echo ""; exit(); }
$uid = $cfg_ml->M_LoginID;
?>
<strong>歡迎您</strong>[<?php echo $cfg_ml->M_UserName?>],現在你可以直接發布留言


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM