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

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

php 用戶cookie登錄驗(yàn)證與mysql數(shù)據(jù)登錄驗(yàn)證的方法

2024-05-04 21:47:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

php用戶cookie登錄驗(yàn)證與mysql數(shù)據(jù)登錄驗(yàn)證的方法:

  1. <?php 
  2. unset($username); 
  3. if ($_COOKIE['login']) { 
  4.     list($c_username,$cookie_hash) = split(',',$_COOKIE['login']); 
  5.     if (md5($c_username.$secret_word) == $cookie_hash) { 
  6.         $username = $c_username
  7.     } else { 
  8.         print "You have sent a bad cookie."
  9.     } 
  10.  
  11. if ($username) { 
  12.     print "Welcome, $username."
  13. else { 
  14.     print "Welcome, anonymous user."
  15. ?> 

看個(gè)完整的與數(shù)據(jù)庫(kù)連接登錄的代碼:

  1. <html> 
  2.  
  3.  <head> 
  4.   <title>Log-In Page</title> 
  5.  </head> 
  6.  
  7.  <body> 
  8.  Please enter your user details to log-in here... 
  9.  
  10.  <form action = "authenticate.php" method = "post"
  11.  Username:<br> 
  12.  <input type = "text" name = "username"
  13.  <br><br> 
  14.  Password:<br> 
  15.  <input type = "text" name = "password"
  16.  <br><br> 
  17.  <input type = "submit" value = "Log In"
  18.  </form> 
  19.  
  20.  </body> 
  21.  
  22. </html> 

File:authenticate.php

  1. <?php 
  2.  
  3. $username = $_POST['username']; 
  4. $password = $_POST['password']; 
  5. $self =     $_SERVER['PHP_SELF']; 
  6. $referer =  $_SERVER['HTTP_REFERER']; 
  7.  
  8. if( ( !$username ) or ( !$password ) ) 
  9. { header( "Location:$referer" ); exit(); } 
  10.  
  11. $conn=@mysql_connect( "localhost""userName""password" ) or die"Could not connect" ); 
  12.  
  13. $rs = @mysql_select_db( "my_database"$conn ) or die"Could not select database" ); 
  14. $sql = "select * from users where user_name="$username" and password = password( "$password" )"
  15.  
  16. $rs = mysql_query( $sql$conn ) or die"Could not execute query" ); 
  17.  
  18. $num = mysql_numrows( $rs ); 
  19.  
  20. if$num != 0 ) 
  21. {  
  22.   $msg = "<h3>Welcome $username - your log-in succeeded!</h3>"
  23. else 
  24.   header( "Location:$referer" ); exit();  
  25. ?> 
  26.  
  27. <html> 
  28.  
  29.  <head> 
  30.   <title>Log-In Authenticated</title> 
  31.   </head> 
  32.  
  33.   <body> 
  34.    <?php echo$msg ); ?> 
  35.   </body> 
  36.  
  37. </html> 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 额尔古纳市| 八宿县| 青岛市| 庆元县| 长垣县| 抚州市| 无锡市| 高台县| 谢通门县| 精河县| 平湖市| 同德县| 寿阳县| 临颍县| 乌苏市| 门头沟区| 明水县| 拉萨市| 平乐县| 汾西县| 钦州市| 永福县| 九龙城区| 磴口县| 临安市| 万山特区| 乐昌市| 芷江| 子长县| 昂仁县| 六安市| 静宁县| 偏关县| 田东县| 嘉峪关市| 迁西县| 独山县| 类乌齐县| 中卫市| 镇巴县| 永丰县|