php面向?qū)ο蟮挠脩舻卿浬矸蒡?yàn)證
更新時間:2017年06月08日 10:48:00 作者:cakin24
這篇文章主要為大家詳細(xì)介紹了php面向?qū)ο蟮挠脩舻卿浬矸蒡?yàn)證,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了php用戶登錄身份驗(yàn)證的具體代碼,供大家參考,具體內(nèi)容如下
一、代碼
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>用戶身份驗(yàn)證</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">用戶身份驗(yàn)證</div></td>
</tr>
<tr>
<td width="60" height="25" bgcolor="#FFFFFF"><div align="center">用戶名:</div></td>
<td width="187" bgcolor="#FFFFFF"><div align="left"> <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"> <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 //定義密碼驗(yàn)證類
{
private $name; //定義用戶名屬性
private $pwd; //定義密碼屬性
public function __construct($x,$y) //構(gòu)造函數(shù),對類的屬性初始化
{
$this->name=$x;
$this->pwd=$y;
}
public function chkuser() //驗(yàn)證用戶身份
{
include_once("conn.php");
$rs=new com("adodb.recordset"); //創(chuàng)建記錄集對象
$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); //對密碼驗(yàn)證類進(jìn)行實(shí)例化
$chk1->chkuser(); //調(diào)用chkuser()方法驗(yàn)證用戶身份
}
?>
</body>
</html>
二、運(yùn)行結(jié)果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- PHP實(shí)現(xiàn)會員賬號單唯一登錄的方法分析
- php $_SESSION會員登錄實(shí)例分享
- PHP+MYSQL會員系統(tǒng)的登陸即權(quán)限判斷實(shí)現(xiàn)代碼
- 實(shí)用PHP會員權(quán)限控制實(shí)現(xiàn)原理分析
- php+MySQL實(shí)現(xiàn)登錄時驗(yàn)證登錄名和密碼是否正確
- php session應(yīng)用實(shí)例 登錄驗(yàn)證
- php cookie 登錄驗(yàn)證示例代碼
- PHP登錄驗(yàn)證碼的實(shí)現(xiàn)與使用方法
- php自動注冊登錄驗(yàn)證機(jī)制實(shí)現(xiàn)代碼
- php 實(shí)現(xiàn)賬號不能同時登陸的方法分析【當(dāng)其它地方登陸時,當(dāng)前賬號失效】
相關(guān)文章
PHP用swoole+websocket和redis實(shí)現(xiàn)web一對一聊天
這篇文章主要介紹了PHP用swoole+websocket和redis實(shí)現(xiàn)web一對一聊天,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Thinkphp5 如何隱藏入口文件index.php(URL重寫)
今天小編就為大家分享一篇Thinkphp5 如何隱藏入口文件index.php(URL重寫),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
淺析PHP反序列化中過濾函數(shù)使用不當(dāng)導(dǎo)致的對象注入問題
這篇文章主要介紹了PHP反序列化中過濾函數(shù)使用不當(dāng)導(dǎo)致的對象注入問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2020-02-02

