-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_sign.php
73 lines (69 loc) · 1.97 KB
/
action_sign.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
<?php
session_start();
if(isset($_SESSION['email'])) {
header("location:index.php");
}
else {
session_destroy();
}
?>
<!doctype html>
<html>
<head>
<title>Signin</title>
<meta http-equiv="refresh" content="2; url=signin.php">
<link href="./assets/css/custom.css" rel="stylesheet">
</head>
<body style="text-align:center;">
<?php
function dataReceive() {
$email = $_POST["email"];
$pass = $_POST["pass"];
$pass = md5($pass);
return array($email, $pass);
}
function databaseConnection() {
$server = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$conn = mysqli_connect($server, $username, $password, $dbname);
if (!$conn) {
echo "<div class=\"action_failure\">";
echo "Connection failed: " . mysqli_error();
echo "</div>";
return null;
}
return $conn;
}
function dataCheck($conn, $email, $pass) {
$sql = "select email from stu where email = '$email' and pass = '$pass'";
$res = mysqli_query($conn, $sql);
if (!$res) {
echo "<div class=\"action_failure\">";
echo "Error: ". $sql . "<br>" . mysqli_error($conn);
echo "</div>";
return;
}
$count = mysqli_num_rows($res);
if ($count == 1) {
session_start();
$_SESSION['email'] = $email;
$_SESSION['pass'] = $pass;
header("Location:index.php");
}
else {
echo "<div class=\"action_failure\">";
echo "Wrong email or password.<br>";
//echo "Go to <a href=\"signin.php\">Sign In</a> page.";
echo "</div>";
}
}
$emailAndPass = dataReceive();
$email = $emailAndPass[0];
$pass = $emailAndPass[1];
$conn = databaseConnection();
dataCheck($conn, $email, $pass);
?>
</body>
</html>