欢迎来到代码驿站!

PHP代码

当前位置:首页 > 软件编程 > PHP代码

php面向对象的用户登录身份验证

时间:2021-05-16 09:38:45|栏目: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"><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">&nbsp;<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">&nbsp;<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> 

二、运行结果

上一篇:关于crontab的使用详解

栏    目:PHP代码

下一篇:PHP中遇到的时区问题解决方法

本文标题:php面向对象的用户登录身份验证

本文地址:http://www.codeinn.net/misctech/122656.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有