1. 程式人生 > >雇員信息管理系統(2)管理員數據庫登錄

雇員信息管理系統(2)管理員數據庫登錄

meta local echo connect 文件的 col orm com span

運行結果如下:

  登錄頁面loginview.php。

技術分享

  按下登錄按鈕,跳轉到登錄處理頁面loginview.phploginprocess.php,進行數據庫查詢後,登錄失敗,跳轉回登錄頁面loginview.php,並提示錯誤信息。

技術分享

  輸入正確的賬號密碼,登錄成功,跳轉到主頁面mainview.php。

技術分享

使用phpMyAdmin創建雇員信息管理數據庫(aedb)過程如下:

  創建雇員信息管理數據庫(aedb)。

技術分享

  在雇員信息管理數據庫(aedb)中,創建管理員表(ad)。

技術分享

  在管理員表(ad)中,插入元組。

  (註:md5()用於加密。下例字符串參數”123“經過md5函數運算後將得到另一個字符串(稱為md5值),無法解密,由此起到加密保護的作用。用於密碼驗證時,需要求出用戶輸入密碼的md5值,若數據庫中經過md5加密的密碼與之相同,則驗證成功。)

技術分享

loginview.php源代碼如下:

技術分享
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title>雇員信息系統</title>
 5     <meta http-equiv = "content-type" content="text/html; charset = utf-8 ">
 6 
 7     <style type="text/css">
 8         div.error{height: 22px; width: 150px; color:red; size:2px;}
9 </style> 10 11 </head> 12 <body bgcolor="#ABC"> 13 <center> 14 <div style="height: 60px; width: 50px"></div> 15 <!--用於調整表單的垂直位置--> 16 <h1 >管理員登錄</h1> 17 <form action="loginprocess.php" method="post" > 18
<table> 19 <tr> 20 <th>賬號</th> 21 <th><input type="text" name="id"></input></th> 22 <th><div class="error"><?php 23 //div,防止表單錯誤信息影響布局 24 //判斷表單錯誤信息的存在和顯示 25 if (isset($_GET[‘error‘])) { 26 $error=$_GET[‘error‘]; 27 }else{ 28 $error=0; 29 } 30 if ($error==1) { 31 echo"*賬號或密碼錯誤!"; 32 } 33 ?></div></th> 34 </tr> 35 <!--tr標簽內是同一行的內容,th標簽內是同一列的內容--> 36 <tr> 37 <th>密碼</th> 38 <th><input type="password" name="password"></input></th> 39 </tr> 40 <tr> 41 <th></th> 42 <th> 43 <input type="submit" value="登錄"></input> 44 <input type="reset" value="重置"></input> 45 </th> 46 </tr> 47 </table> 48 </form> 49 </center> 50 </body> 51 </html>
loginview.php

loginprocess.php源代碼如下:

技術分享
 1 <?php
 2 ////設置php文件的編碼
 3     header("Content-type:text/html;charset=utf-8");
 4 //接受用戶數據
 5     $id=$_POST[‘id‘];
 6     $password=$_POST[‘password‘];
 7 //得到連接
 8     $conn=mysql_connect("localhost","root","root");
 9     if (!$conn) {
10         die("連接失敗!錯誤信息:".mysql_errno());
11     }
12 //設置訪問數據庫的編碼
13     mysql_query("set names utf8",$conn) or die("設置編碼失敗!錯誤信息:".mysql_errno());
14 //選擇數據庫
15     mysql_select_db("aedb",$conn) or die("選擇數據庫失敗!錯誤信息:".mysql_errno());
16 //發送SQL語句
17     $sql="SELECT password FROM ad WHERE id=$id";
18 //獲取查詢結果集
19     $res=mysql_query($sql,$conn);
20 //判斷查詢結果是否存在及是否完全匹配
21 //md5(),計算機安全領域廣泛使用的一種散列函數,用以提供消息的完整性保護。
22     if (($row=mysql_fetch_assoc($res)) && $row[‘password‘]==md5($password)) {
23 //匹配成功,跳轉到mainview.php
24         header("Location:mainview.php");
25         die();
26     }
27 //匹配失敗,跳轉到loginview.php,並發送錯誤信息error
28         header("Location:loginview.php?error=1");
29         die();
30 ?>
loginprocess.php

mainview.php源代碼如下:

技術分享
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title>歡迎使用雇員信息管理系統</title>
 5     <meta http-equiv = "content-type" content="text/html; charset = utf-8 ">
 6 
 7     <style type="text/css">
 8         div.d0{color:red; size:200px; font-weight:700;text-align:center;}
 9     </style>
10 
11 </head>
12 <body bgcolor="#ABC" >
13     <div class="d0">登錄成功!!</div>
14 </body>
15 </html>
mainview.php

雇員信息管理系統(2)管理員數據庫登錄