-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
49 lines (41 loc) · 1.37 KB
/
signup.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
<?php
include 'database.php';
$con = init_db();
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "INSERT INTO
User (user_name, password, email)
VALUES
('" . mysqli_real_escape_string($con, $_POST['username']) . "',
'" . sha1($_POST['password']) . "',
'" . mysqli_real_escape_string($con, $_POST['email']) . "'
)";
$result = mysqli_query($con, $sql);
if(!$result) {
echo mysqli_error($con);
}
else {
$sql = "SELECT
id,
user_name
FROM
User
WHERE
email = '" . mysqli_real_escape_string($con, $_POST['email']) . "'
AND
password = '" . sha1($_POST['password']) . "'";
$result = mysqli_query($con, $sql);
if($result) {
session_start();
$_SESSION['signed_in'] = true;
while($row = mysqli_fetch_assoc($result)) {
$_SESSION['user_id'] = $row['id'];
$_SESSION['user_name'] = $row['user_name'];
}
}
// Redirect back to the previous page
$referer = $_SERVER['HTTP_REFERER'];
header("Location: $referer");
}
}
mysqli_close($con);
?>