php物件導向的使用者登入驗證

陈政宽~
發布: 2023-03-11 20:18:01
原創
1562 人瀏覽過

這篇文章主要為大家詳細介紹了php物件導向使用者登入身份驗證,具有一定的參考價值,有興趣的小夥伴們可以參考一下

本文實例為大家分享了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"><p align="center" class="STYLE1">用户身份验证</p></td> 
   </tr> 
   <tr> 
    <td width="60" height="25" bgcolor="#FFFFFF"><p align="center">用户名:</p></td> 
    <td width="187" bgcolor="#FFFFFF"><p align="left"> <input type="text" name="username" size="22" class="inputcss"></p></td> 
   </tr> 
   <tr> 
    <td height="25" bgcolor="#FFFFFF"><p align="center">密码:</p></td> 
    <td height="25" bgcolor="#FFFFFF"><p align="left"> <input type="password" name="userpwd" size="22" class="inputcss"></p></td> 
   </tr> 
   <tr> 
    <td height="25" colspan="2" bgcolor="#FFFFFF"><p align="center"><input name="submit" type="submit" value="登录" class="buttoncss"></p></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(&#39;请输入用户名或用户密码!&#39;);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=&#39;".$this->name."&#39; and userpwd=&#39;".$this->pwd."&#39;",$conn,3,1);  
      if($rs->eof || $rs->bof) 
       { 
        echo "<script>alert(&#39;对不起,密码或用户名错误!&#39;);history.back();</script>"; 
        exit; 
       } 
      else 
       { 
        echo "<script>alert(&#39;恭喜您登录成功!&#39;);history.back();</script>"; 
        exit; 
       } 
     } 
   } 
  $chk1=new chk($username,$userpwd);  //对密码验证类进行实例化  
  $chk1->chkuser();   //调用chkuser()方法验证用户身份 
    
 } 
?> 
</body> 
</html>
登入後複製

二、運行結果

######以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本家。 ###

以上是php物件導向的使用者登入驗證的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!