學用PHP編寫MySQL資料庫的使用者認證系統

來源:互聯網
上載者:User

戶認證的原理很簡單:首先需要使用者在頁面上填入使用者名稱和密碼,當然沒註冊的使用者需要先註冊。然後調用資料庫搜尋是否有相應的使用者。如果有就確認,沒有則提醒使用者先註冊。使用PHP來完成這一切很簡單,但需要注意的是如果想在以後的頁面中都能確認使用者身份。
第一步是做一個登入的頁面。

第二步開始登入後的確認程式的設計。


login.php: 
mysql_connect("localhost","user","password")
/*串連資料庫,使用者名稱和密碼自行修改*/
or die("無法串連資料庫,請重試");

mysql_select_db("userinfo")
or die("無法選擇資料庫,請重試");
$today=date("Y-m-d H:i:s");

$query="
select id
from usertbl
where name=$name and password=$password
/*從資料庫中搜尋和登入使用者相應的資料*/
";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);

if($numrows==0){
/*驗證是否能找出相同資料的使用者,不能則未註冊*/
echo 非法使用者
;
echo 請註冊先
;
echo 重試
;
}

else{
$row=mysql_fetch_array($result);
$id=$row[0];
$query="
update usertbl
set lastlogin=$today
where id=$id";
$result=mysql_query($query);
SetCookie("usercookie", "歡迎你,$name");
 /*這裡使用了cookie,以方便之後的頁面認證。
但我未開發完這一塊。希望有興趣的朋友指正*/
echo 登入成功
;
echo 請進!
;
}
?>

  • 1
  • 2
  • 下一頁
【內容導航】
第1頁:學用PHP編寫MySQL資料庫的使用者認證系統 第2頁:學用PHP編寫MySQL資料庫的使用者認證系統

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.