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

首頁 > 開發 > PHP > 正文

php用戶登錄代碼,cookie,數據庫

2024-05-04 21:59:01
字體:
來源:轉載
供稿:網友

下面我們要講到二種用戶登錄方法一種是利用window驗證加數據庫密碼驗證實現登錄,后者是利用cookie記錄用戶信息進行登錄,有需要的朋友可以試下.

  1. <?php 
  2.    function authenticate_user() { 
  3.       header('WWW-Authenticate: Basic realm="Secret Stash"'); 
  4.       header("HTTP/1.0 401 Unauthorized"); 
  5.       exit
  6.    } 
  7.  
  8.    if (! isset($_SERVER['PHP_AUTH_USER'])) { 
  9.       authenticate_user(); 
  10.    } else { 
  11.       mysql_pconnect("localhost","authenticator","secret"or die("Can't connect to database server!"); 
  12.       mysql_select_db("java2s"or die("Can't select authentication database!"); 
  13.  
  14.       $query = "SELECT username, ps教程wd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')"
  15. //開源代碼Vevb.com 
  16.       $result = mysql_query($query); 
  17.  
  18.       // If nothing was found, reprompt the user for the login www.111cn.net information. 
  19.       if (mysql_num_rows($result) == 0) { 
  20.          authenticate_user(); 
  21.       } 
  22.    } 
  23. ?> 

利用cookie登錄方法,實例代碼如下:

  1. <html> 
  2.   <head> 
  3.   <title>Enter Password</title> 
  4.   </head> 
  5.   <body> 
  6.   <form name="forml" method="POST" action="CookieBasedPasswordLogin.php"
  7.     <table> 
  8.       <tr> 
  9.        <td colspan="2" > 
  10.          <div align="center"><b>Please Specify the Password</b></div> 
  11.        </td> 
  12.      </tr> 
  13.    <tr>> 
  14.      <td> 
  15.        <div align="right">Customer ID</div> 
  16.      </td> 
  17.      <td> 
  18.        <input type="text" name="username"
  19.      </td> 
  20.    </tr> 
  21.    <tr> 
  22.      <td> 
  23.        <div align="right">Password</div> 
  24.      </td> 
  25.      <td> 
  26.        <input type="password" name="password"
  27.      </td> 
  28.    </tr> 
  29.    <tr> 
  30.      <td colspan="2"
  31.        <center> 
  32.          <input type="submit" name="Submit" value="Login"
  33.        </center> 
  34.      </td> 
  35.     </tr> 
  36.    </table> 
  37.   </form> 
  38.   </body> 
  39.   </html> 
  40. <!-- CookieBasedPasswordLogin.php 
  41. <?php 
  42.     $now = getdate(); 
  43.     $storetime$now["weekday"] . " " . $now["month"] ." " . $now["year"] ; 
  44.     $storetime.=" Time : "
  45.  
  46.     if ($now["hours"] < 10) { 
  47.       $storetime.= "0" . $now["hours"]; 
  48.     } else { 
  49.       $storetime.= $now["hours"]; 
  50.     } 
  51.    
  52.     $storetime.= ":"
  53.     if ($now["minutes"]<10) { 
  54.       $storetime.= "0" . $now["minutes"]; 
  55.     } else { 
  56.       $storetime.= $now["minutes"]; 
  57.     } 
  58.      
  59.     $storetime.= ": "
  60.     if ($now["seconds"] <10) { 
  61.       $storetime.= "0" . $now["seconds"]; 
  62.     } else { 
  63.       $storetime.= $now["seconds"]; 
  64.     } 
  65.     if (isset($data)) { 
  66.        $counter=++$data[l]; 
  67.         setcookie("data[0]",$storetime,time() + (60*60*24)); 
  68.         setcookie("data[l]"$counter,time() + (60*60*24)); setcookie("data[2]",$username,time() + (60*60*24)); 
  69.         echo "<b><center>Hi " . $data[2] . " ! !</center></b><br>n"
  70.         echo "<b><center>Last Login Time :" .$data[0] . "</center></b><br>n"
  71.         echo "<b><center>Current Date :" .$storetime"</center></b><br>n"
  72.         echo "<b><center>Page View Count :" . $data[l]. "</center></b><br>n"
  73.         echo "<b><center>You have successfully logged in!</center></b>"
  74.         echo ("<b><contor>You can access this area without entering a password for the next 24 hours!</center></b>"); 
  75.    } else { 
  76.     if (isset($username) && isset($password)) { 
  77.      if ($password=="superpass") { 
  78.           $counter=0; 
  79.           setcookie("data[0]",$storetime,time() + (60*60*24)); 
  80.           setcookie("data[l]",$counter,time() + (60*60*24)); 
  81.           setcookie("data[2]",$username,time() + (60*60*24)); 
  82.           $url="Location: cookieimp.php"
  83.           header($url); 
  84.      }else
  85.           echo "<hl><center>INVALID PASSWORD!!!</center></hl>"
  86.      } 
  87.     } 
  88.   } 
  89.   ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富顺县| 邹平县| 荃湾区| 双桥区| 格尔木市| 平江县| 泸西县| 富裕县| 林周县| 隆化县| 邵阳市| 洞口县| 昌江| 铅山县| 贵港市| 揭东县| 宁陵县| 三门县| 江都市| 松溪县| 庄河市| 天水市| 辉南县| 马边| 铜陵市| 扎赉特旗| 肇州县| 洛扎县| 光泽县| 博兴县| 阿合奇县| 巴塘县| 中超| 西乌珠穆沁旗| 汉源县| 岚皋县| 鹤岗市| 承德市| 肥东县| 黄平县| 横峰县|