php使用面向对象实现用户登录身份验证的功能
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php使用面向对象实现用户登录身份验证的功能,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2912字,纯文字阅读大概需要5分钟。
内容图文
![php使用面向对象实现用户登录身份验证的功能](/upload/InfoBanner/zyjiaocheng/145/309ffeb8de074c2aa76b6de17bee7dbd.jpg)
本文实例为大家分享了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('请输入用户名或用户密码!');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>
二、运行结果
以上就是php使用面向对象实现用户登录身份验证的功能的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的php使用面向对象实现用户登录身份验证的功能全部内容,希望文章能够帮你解决php使用面向对象实现用户登录身份验证的功能所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。