国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 恩平市| 东宁县| 广西| 棋牌| 渭南市| 余干县| 宁阳县| 天镇县| 彭山县| 洛阳市| 五河县| 武隆县| 娄烦县| 澄城县| 黔西县| 东海县| 长岭县| 长宁区| 博乐市| 胶南市| 铜川市| 红原县| 五华县| 昭苏县| 西吉县| 西和县| 旬阳县| 叙永县| 庆元县| 科尔| 阿拉善盟| 扎囊县| 砀山县| 浏阳市| 丰顺县| 兰西县| 云和县| 普兰店市| 盖州市| 固镇县| 宁晋县|