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 type="text/css" href="https://www.jb51.net/css/style.css" > <style type="text/css"> <!-- .STYLE1 {color: #FFFFFF} --> </style> </head> <body> <table cellpadding="1" cellspacing="0"> <tr> <td bgcolor="#0099CC"><table cellpadding="0" cellspacing="1"> <form method="post" action="index.php"> <tr> <td colspan="2" bgcolor="#0099CC"><div>用户身份验证</div></td> </tr> <tr> <td bgcolor="#FFFFFF"><div>用户名:</div></td> <td bgcolor="#FFFFFF"><div>&nbsp;<input type="text" size="22"></div></td> </tr> <tr> <td bgcolor="#FFFFFF"><div>密码:</div></td> <td bgcolor="#FFFFFF"><div>&nbsp;<input type="password" size="22"></div></td> </tr> <tr> <td colspan="2" bgcolor="#FFFFFF"><div><input type="submit" value="登录"></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>

二、运行结果

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1ca358e7a4c5729480f13f4a0858d933.html