登录  /  注册

php使用面向对象实现用户登录身份验证的功能

怪我咯
发布: 2018-05-15 17:38:04
原创
3609人浏览过

这篇文章主要为大家详细介绍了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中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号