ホームページ > バックエンド開発 > PHPチュートリアル > phpオブジェクト指向のユーザーログイン認証

phpオブジェクト指向のユーザーログイン認証

陈政宽~
リリース: 2023-03-11 20:18:01
オリジナル
1734 人が閲覧しました

この記事では、主に ユーザー ログイン の ID 検証について詳しく紹介します。興味のある方は参考にしてください。この記事の例では、PHP のユーザー ログイン ID を共有します。検証用の具体的なコードは以下の通りです

1. コード

conn.php

1

2

3

4

5

<strong><?php

$conn = new com("adodb.connection"); 

$connstr="driver={microsoft access driver (*.mdb)}; dbq=". realpath("data/db_database07_188.mdb");

$conn->open($connstr);

?></strong>

ログイン後にコピー
index.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

<!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>

ログイン後にコピー

2. 実行結果

以上です。すべてはこの記事のために この内容が皆さんの学習に役立つことを願っています。また、皆さんが Script House をサポートしてくれることを願っています。

以上がphpオブジェクト指向のユーザーログイン認証の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
PHP 拡張子 intl
から 1970-01-01 08:00:00
0
0
0
phpのデータ取得?
から 1970-01-01 08:00:00
0
0
0
PHP GET エラー レポート
から 1970-01-01 08:00:00
0
0
0
phpを上手に学ぶ方法
から 1970-01-01 08:00:00
0
0
0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート