>  기사  >  백엔드 개발  >  PHP 객체지향 사용자 로그인 인증

PHP 객체지향 사용자 로그인 인증

陈政宽~
陈政宽~원래의
2017-06-28 13:35:411592검색

이 글은 사용자 로그인신원 확인에 대해 주로 객체 지향을 소개합니다. 관심 있는 친구들이 참고할 수 있습니다.

이 글의 예는 모든 사람과 PHP 사용자 로그인 ID를 공유합니다. 구체적인 검증 코드는 참고용입니다.

1. 코드

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>

2. 실행 결과

입니다. 이 기사의 모든 내용은 모든 사람의 학습에 도움이 되기를 바라며, 또한 모든 사람이 Script Home을 지원하기를 바랍니다.

위 내용은 PHP 객체지향 사용자 로그인 인증의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.