国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php登錄與退出登錄實例代碼

2024-05-04 21:57:37
字體:
來源:轉載
供稿:網(wǎng)友

這里我們pm_user是數(shù)據(jù)表沒有創(chuàng)建表,大家可以自己行創(chuàng)建了,下面只介紹利用php登錄然后再退出登錄的程序代碼,有需要的朋友可進行參考.

login.htm

實例代碼如下:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <title>無標題文檔</title> 
  6. </head> 
  7. <body> 
  8. <form id="form1" name="form1" method="post" action=""
  9.   <p> 
  10.     <label for="user"></label> 
  11.     <input type="text" name="user" id="user" /> 
  12.   </p> 
  13.   <p> 
  14.     <label for="pwd"></label> 
  15.     <input type="text" name="pwd" id="pwd" /> 
  16.   </p> 
  17.   <p> 
  18.     <input type="submit" name="button" id="button" value="提交" /> 
  19.   </p> 
  20. </form> 
  21. </body> 
  22. </html> 

login.php

實例代碼如下:

  1. function showPage() //判斷是否登錄 未登錄直接跳轉至登錄頁面 
  2.  if(!isset($_SESSION["user"]) && !isset($_SESSION["pwd"])) 
  3.  { 
  4.   if(isset($_COOKIE["user"]) && isset($_COOKIE["pwd"])) 
  5.   { 
  6.    $sql = "select * from pm_user where u_user='$_COOKIE[user]'"
  7.    $query = mysql_query($sql); 
  8.    $isUser = is_array($row = mysql_fetch_array($query)); //判斷用戶名 
  9.    $isPwd = $isUser ? $row["u_pwd"] == $_COOKIE["pwd"] : false; //判斷密碼 
  10.    if($isPwd
  11.    { 
  12.     $_SESSION["user"]  = $_COOKIE["user"]; 
  13.     $_SESSION["pwd"]   = $_COOKIE["pwd"]; 
  14.     $_SESSION["id"]    = $_COOKIE["id"]; 
  15.     $_SESSION["name"]  = $_COOKIE["name"]; 
  16.    } 
  17.   } 
  18.  } 
  19.  
  20.  if(!isset($_SESSION["user"]) && !isset($_SESSION["pwd"])) 
  21.  { 
  22.   echo '<script>alert("你還沒登錄!正在返回登錄頁面...");location.href="index.php";</script>'
  23.   exit(); 
  24.  } 

退出登錄

out.php

實例代碼如下:

  1. function loginOut() //登出函數(shù) 
  2.  if(isset($_GET["login"]) == 'out'
  3.  { 
  4.   $_SESSION["user"]  = ''
  5.   $_SESSION["pwd"]   = ''
  6.   $_SESSION["id"]    = ''
  7.   $_SESSION["name"]  = ''
  8.   session_destroy(); 
  9.   echo '<script>alert("退出成功!");location.href="index.php"; </script>'
  10.  } 

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 桓仁| 固镇县| 新兴县| 仁寿县| 当阳市| 邛崃市| 佛坪县| 抚松县| 铁力市| 措勤县| 轮台县| 中阳县| 峡江县| 漳浦县| 双流县| 广州市| 湄潭县| 白朗县| 迭部县| 资阳市| 珠海市| 建宁县| 饶河县| 定安县| 阿拉善左旗| 攀枝花市| 慈利县| 瑞昌市| 崇义县| 全椒县| 房产| 太仆寺旗| 合肥市| 岳西县| 卓尼县| 崇仁县| 蒙城县| 富裕县| 友谊县| 海原县| 新晃|