-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
122 lines (98 loc) · 3.88 KB
/
signup.php
File metadata and controls
122 lines (98 loc) · 3.88 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
include 'sqlconnect.php';
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Sign up!!</title>
<link rel="stylesheet" href="/megastyles.css">
</head>
<body>
<p class = "heading"> Create your own account!!!<br><br></p>
<div class = "side-heading"> <p>Welcome to your own calendar</p>
<ul class = "list" >
You can.....
<li>Create an account</li>
<li>Create your own appointments. </li>
<li>Manage them, schedule invites with other people</li>
</ul>
</div>
<?php
function print_form(){
echo '<div class = "loginform">';
echo '<form class="form" action="/signup.php" method="post" id = "signup">';
echo '<span class = "username"> Enter your username here:- </span>';
echo '<input class = "username" type="text" name="name" placeholder="enter your name here" id = "userinputname" required/> <span class = "error" id = "wrong"></span><span class = "correct" id = "correct"></span><br>';
echo '<span class = "username"> Enter your nickname:-</span>';
echo '<input class = "username" type="text" name="nick" required > <br>';
echo '<span class = "username"> Enter your password :- </span>';
echo '<input class = "username" type="password" name="password" value="" required> <br><br>';
echo '<img id = "captcha" src = "/captcha.php" alt = "captcha" width = "200" height = "50" class = "captcha">';
echo ' <input type="text" name="captcha" placeholder = "Enter captcha text here" required>';
echo '<input type = "button" onclick = "reloadcaptcha()" Value = "Reload"/><br><br>';
echo '<input type="hidden" name="stage" value="process">';
echo '<input type="submit" name="submit" value="Create My Account" id = "submit" class = "submit">';
echo '</form>';
echo '</div>';
}
// echo $_SESSION['code'];
if(isset($_POST['stage']) && $_POST['stage']=='process')
process_form();
else print_form();
function process_form(){
$conn = mysqli_connect("localhost", "username","password", "deltadb");
if($_POST['captcha'] != $_SESSION['code']) {
echo '<p class = "error">Invalid captcha</p>';
print_form();
}
else{
$name = $_POST['name'];
$_SESSION['signup'] = "success";
$nick = $_POST['nick'];
$password = crypt($_POST['password'], '34');
$stmt = mysqli_prepare($conn, "INSERT INTO deltadb.logintable VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sss', $name, $password, $nick);
mysqli_execute($stmt);
echo '<script type="text/javascript">';
echo 'document.location.replace("/login.php")';
echo '</script>';
}
}
?>
<p class = "log">Already have an account? <br>Click <a href="login.php"> here </a> to log in! </p>
</body>
<script type="text/javascript">
function reloadcaptcha(){
document.getElementById('captcha').src = "/captcha.php?" + new Date().getTime();
}
var input = document.getElementById('userinputname');
var str;
var xhr = new XMLHttpRequest();
var form = document.getElementById('signup');
function sendUsername(){
str = input.value;
console.log(str);
xhr.open("GET","formvalidate.php?name=" + str);
xhr.send();
}
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200) {
if(xhr.responseText == "Name is already taken")
{
document.getElementById('wrong').innerHTML = xhr.responseText;
document.getElementById('correct').innerHTML = "";
document.getElementById('submit').disabled = true;
document.getElementById('wrong').style.color = "red";
}
else{
document.getElementById('wrong').innerHTML = "";
document.getElementById('correct').innerHTML = xhr.responseText;
document.getElementById('submit').disabled = false;
document.getElementById('correct').style.color = "green";
}
}
};
input.addEventListener('input', sendUsername);
</script>
</html>