管理登入功能和會員登入功能幾乎一樣,差別在於管理登入的資料表中有一個權限的欄位我們採用序列化的字串來儲存。
- 把
./view/front/login.php
中的程式碼複製一份到./view/front/admin_login.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<h2 class="ct">管理者登入</h2>
<table class="all">
<tr>
<td class="tt ct">帳號</td>
<td class="pp"><input type="text" name="acc" id="acc"></td>
</tr>
<tr>
<td class="tt ct">密碼</td>
<td class="pp"><input type="password" name="pw" id="pw"></td>
</tr>
<tr>
<td class="tt ct">驗證碼</td>
<td class="pp">
<?php
$a=rand(10,99);
$b=rand(10,99);
$_SESSION['ans']=$a+$b;
echo "{$a} + {$b} = ";
?>
<input type="text" name="ans" id="ans"></td>
</tr>
</table>
<div class="ct">
<button onclick="login('Admin')">確認</button>
</div> - 由於js函式login()已經寫在
/js/js.js
中了,因此只要變更參數為Admin
就可以了
補充
如果要測試管理者帳號的話,可以先手動在資料表中塞一筆資料,而權限的字串我們可以先做一個測試用的php來產生這個序列化的字串,並寫入到資料表中
1 | //手動產生一筆管理者資料進db |