-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·76 lines (65 loc) · 2.62 KB
/
index.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
74
75
76
<?php
session_start();
require_once "essentials/functions.php";
$error_message = "";
if ( isset($_SESSION["USER_ID"]) ) {
// redirect the user to chat page in case the user_id variable exists
redirect("/pages/chat.php");
exit;
}
elseif ( isset($_POST["login"]) ){
if ( isset($_POST["fullname"]) ){
// the coming 2nd line of this statement will switch the name of the user to leet chars
// in case he/she checked the checkbox
$fullname = htmlspecialchars( $_POST["fullname"] );
$nickname = htmlspecialchars( isset($_POST["leet"]) ? strtr($_POST["fullname"], 'letsoa', '137504') : $_POST["fullname"] );
if ( ($id = addUser($fullname)) !== false ) {
// creating account if the user is not already exist in the database
$_SESSION["CURRENT_USER_ID"] = $id;
redirect("/pages/chat.php");
}
else {
$error_message = "Error: The fullname and nickname already exist, choose another one.";
}
}
else {
$error_message = "Error: Please fill the entries with valid information.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="/styles/main.css">
<title>Hacker Room - Chat With Special People!</title>
</head>
<body class="login">
<form method="POST" action="/index.php">
<table>
<tr>
<td colspan="3" class="login-title">
<h2>Hi... Time to say godbye!</h2>
</td>
</tr>
<tr>
<td class="label-container"><label>Fullname: </label></td>
<td colspan="2"><input type="text" name="fullname" placeholder="Enter your full name..." required></td>
</tr>
<tr>
<td class="label-container"><label>Leet</label></td>
<td><input type="checkbox" name="leet" value="true"></td>
<td><button name="login" value="OK">Login</button></td>
</tr>
</table>
<p class="error-paragraph">
<?php
echo $error_message;
?>
</p>
</form>
</body>
</html>