-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.php
More file actions
30 lines (28 loc) · 959 Bytes
/
connect.php
File metadata and controls
30 lines (28 loc) · 959 Bytes
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
<?php session_start(); ?>
<!--上方語法為啟用session,此語法要放在網頁最前方-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
//連接資料庫
//只要此頁面上有用到連接MySQL就要include它
include("mysqlconnect.php");
$id = $_POST['form-username'];
$pw = $_POST['form-password'];
//搜尋資料庫資料
$sql = "SELECT * FROM member where username = '$id'";
$result = mysql_query($sql);
$row = @mysql_fetch_row($result);
//判斷帳號與密碼是否為空白
//以及MySQL資料庫裡是否有這個會員
if($id != null && $pw != null && $row[1] == $id && $row[2] == $pw)
{
//將帳號寫入session,方便驗證使用者身份
$_SESSION['form-username'] = $id;
echo '登入成功!';
echo '<meta http-equiv=REFRESH CONTENT=1;url=Official website.php>';
}
else
{
echo '登入失敗!';
echo '<meta http-equiv=REFRESH CONTENT=1;url=index.php>';
}
?>