本文實例為大家分享了php用戶登錄身份驗證的具體代碼,供大家參考,具體內容如下
一、代碼
conn.php
<?php $conn = new com("adodb.connection"); $connstr="driver={microsoft access driver (*.mdb)}; dbq=". realpath("data/db_database07_188.mdb"); $conn->open($connstr); ?>
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>用戶身份驗證</title> <link rel="stylesheet" type="text/css" href="css/style.css" rel="external nofollow" > <style type="text/css"> <!-- .STYLE1 {color: #FFFFFF} --> </style> </head> <body> <table width="250" border="0" align="center" cellpadding="1" cellspacing="0"> <tr> <td height="75" bgcolor="#0099CC"><table width="250" height="75" border="0" cellpadding="0" cellspacing="1"> <form name="form1" method="post" action="index.php"> <tr> <td height="25" colspan="2" bgcolor="#0099CC"><div align="center" class="STYLE1">用戶身份驗證</div></td> </tr> <tr> <td width="60" height="25" bgcolor="#FFFFFF"><div align="center">用戶名:</div></td> <td width="187" bgcolor="#FFFFFF"><div align="left"> <input type="text" name="username" size="22" class="inputcss"></div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">密碼:</div></td> <td height="25" bgcolor="#FFFFFF"><div align="left"> <input type="password" name="userpwd" size="22" class="inputcss"></div></td> </tr> <tr> <td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center"><input name="submit" type="submit" value="登錄" class="buttoncss"></div></td> </tr> </form> </table></td> </tr> </table> <?php if($_POST[submit]!="") { $username=$_POST[username]; //接收提交的用戶名 $userpwd=$_POST[userpwd]; //接收提交的密碼 if(trim($username)==""||trim($userpwd)=="") { echo "<script>alert('請輸入用戶名或用戶密碼!');history.back();</script>"; exit; } class chk //定義密碼驗證類 { private $name; //定義用戶名屬性 private $pwd; //定義密碼屬性 public function __construct($x,$y) //構造函數,對類的屬性初始化 { $this->name=$x; $this->pwd=$y; } public function chkuser() //驗證用戶身份 { include_once("conn.php"); $rs=new com("adodb.recordset"); //創建記錄集對象 $rs->open("select * from tb_user where username='".$this->name."' and userpwd='".$this->pwd."'",$conn,3,1); if($rs->eof || $rs->bof) { echo "<script>alert('對不起,密碼或用戶名錯誤!');history.back();</script>"; exit; } else { echo "<script>alert('恭喜您登錄成功!');history.back();</script>"; exit; } } } $chk1=new chk($username,$userpwd); //對密碼驗證類進行實例化 $chk1->chkuser(); //調用chkuser()方法驗證用戶身份 } ?> </body> </html>
二、運行結果
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。