Skip to content

Commit e29a38c

Browse files
committed
bug fixes login page
1 parent ea38c3f commit e29a38c

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

login.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44

55
date_default_timezone_set('Asia/Taipei');
66

7-
$host = $_SERVER['HTTP_HOST'];
8-
$ruta = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
9-
$url = "http://$host$ruta";
10-
117
if (isset($_POST["cancel"])) {
12-
header("Location: $url/index.php");
8+
header("Location: ./index.php");
139
die();
1410
}
1511

1612
if (isset($_COOKIE['email']) && isset($_COOKIE['password'])) {
17-
unset($SESSION["username"]);
18-
unset($SESSION["user_id"]);
13+
unset($_SESSION["username"]);
14+
unset($_SESSION["user_id"]);
1915
session_destroy();
2016
session_start();
2117
$salt = getenv('SALT');
@@ -36,7 +32,7 @@
3632
if ($row['disabled'] === "True") {
3733
$_SESSION["error"] = "Account disabled";
3834
error_log("Login fail disabled account " . $_COOKIE['email'] . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
39-
header("Location: $url/login.php");
35+
header("Location: ./login.php");
4036
die();
4137
}
4238
if ($_COOKIE['email'] == 'g4o2@protonmail.com' || $_COOKIE['email'] == 'g4o3@protonmail.com' || $_POST["email"] == 'maxhu787@gmail.com') {
@@ -48,25 +44,25 @@
4844
$_SESSION["username"] = $row["username"];
4945
$_SESSION['email'] = $row['email'];
5046
$_SESSION["success"] = "Logged in.";
51-
if(isset($_GET['page'])) {
52-
if($_GET['page'] == 'chat') {
53-
header("Location: $url/chat/chat.php");
47+
if (isset($_GET['page'])) {
48+
if ($_GET['page'] == 'chat') {
49+
header("Location: ./chat/chat.php");
5450
}
5551
} else {
56-
header("Location: $url/index.php");
52+
header("Location: ./index.php");
5753
}
5854
die();
5955
} else {
6056
$_SESSION["error"] = "Incorrect email or password";
6157
error_log("Login fail wrong password " . $_COOKIE['email'] . " " . $check . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
62-
header("Location: $url/login.php");
58+
header("Location: ./login.php");
6359
die();
6460
}
6561
}
6662

6763
if (isset($_POST["email"]) && isset($_POST["pass"])) {
68-
unset($SESSION["username"]);
69-
unset($SESSION["user_id"]);
64+
unset($_SESSION["username"]);
65+
unset($_SESSION["user_id"]);
7066
session_destroy();
7167
session_start();
7268
$salt = getenv('SALT');
@@ -87,7 +83,7 @@
8783
if ($row['disabled'] === "True") {
8884
$_SESSION["error"] = "Account disabled";
8985
error_log("Login fail disabled account " . $_POST['email'] . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
90-
header("Location: $url/login.php");
86+
header("Location: ./login.php");
9187
die();
9288
}
9389
if ($_POST["email"] == 'g4o2@protonmail.com' || $_POST["email"] == 'g4o3@protonmail.com' || $_POST["email"] == 'maxhu787@gmail.com') {
@@ -106,16 +102,16 @@
106102
}
107103
if (isset($_GET['page'])) {
108104
if ($_GET['page'] == 'chat') {
109-
header("Location: $url/chat/chat.php");
105+
header("Location: ./chat/chat.php");
110106
}
111107
} else {
112-
header("Location: $url/index.php");
108+
header("Location: ./index.php");
113109
}
114110
die();
115111
} else {
116112
$_SESSION["error"] = "Incorrect email or password";
117113
error_log("Login fail wrong password " . $_POST['email'] . " " . $check . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
118-
header("Location: $url/login.php");
114+
header("Location: ./login.php");
119115
die();
120116
}
121117
}
@@ -185,7 +181,7 @@
185181
</head>
186182

187183
<body class="text-center">
188-
<form class="form-signin" method="post">
184+
<form class="form-signin" method="post" onsubmit="return doValidate();">
189185
<img class="mb-4" src="./favicon.ico" alt="" width="72" height="72">
190186
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
191187
<p>
@@ -200,16 +196,16 @@
200196
}
201197
?>
202198
</p>
203-
<label for="inputEmail" class="sr-only">Email address</label>
199+
<label for="id_email" class="sr-only">Email address</label>
204200
<input type="email" id="id_email" class="form-control" name="email" placeholder="Email address" required="" autofocus="">
205-
<label for="inputPassword" class="sr-only">Password</label>
201+
<label for="id_pass" class="sr-only">Password</label>
206202
<input type="password" id="id_pass" class="form-control" name="pass" placeholder="Password" required="">
207203
<div class="checkbox mb-3">
208204
<label>
209205
<input type="checkbox" name="remember" value="remember" checked> Remember me
210206
</label>
211207
</div>
212-
<button class="btn btn-lg btn-primary btn-block" type="submit" onclick="return doValidate();">Sign in</button>
208+
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
213209
<p class="mt-5 mb-3 text-muted">© <?= date("Y") ?></p>
214210
<p>Don't have an account yet? <a href='./signup.php'>register</a></p>
215211
</form>

logs/logs.log

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,10 @@ Login fail wrong password fff@fff.com 8b7e3e29d811ae8d658113107bb3fb16 209.23.10
201201
Login success maxhu787@gmail.com 220.142.231.39 (Sat, 22 Apr 2023 18:07:48 +0800)
202202
Login success maxhu787@gmail.com 220.142.231.39 (Sat, 22 Apr 2023 21:18:19 +0800)
203203
Logout success (Fri, 26 May 2023 22:23:13 +0800)
204+
Logout success g4o2@protonmail.com (Fri, 26 May 2023 23:38:20 +0800)
205+
Logout success g4o2@protonmail.com (Fri, 26 May 2023 23:38:28 +0800)
206+
Logout success g4o2@protonmail.com (Fri, 26 May 2023 23:38:46 +0800)
207+
Login fail wrong password e@e.e 45c4fd97cdd8eb4e85749cf13b518cea (Fri, 26 May 2023 23:39:35 +0800)
208+
Login fail wrong password awe2@protonmail.com 45c4fd97cdd8eb4e85749cf13b518cea (Fri, 26 May 2023 23:39:50 +0800)
209+
Login fail wrong password g4o2@aweaweprotonmail.com 45c4fd97cdd8eb4e85749cf13b518cea (Fri, 26 May 2023 23:39:54 +0800)
210+
Login fail wrong password g4o2@aweaweprotonmail.com 45c4fd97cdd8eb4e85749cf13b518cea (Fri, 26 May 2023 23:40:03 +0800)

0 commit comments

Comments
 (0)