-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
143 lines (139 loc) · 6 KB
/
register.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
session_start();
if(isset($_SESSION["user"])){
header('location:judge/index.php');
}
?>
<?php
if(isset($_POST["username"])){
$username = htmlspecialchars(addslashes($_POST['username']));
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$name = htmlspecialchars(addslashes($_POST['name']));
$rollno = htmlspecialchars(addslashes($_POST['rollno']));
$email = htmlspecialchars(addslashes($_POST['email']));
$phno = htmlspecialchars(addslashes($_POST['phno']));
$error = "";
if(strlen($username)<4){
$error = "Username too short. Minimum 1 characters";
}
else if(strlen($username)>20){
$error = "Username too long. Maximum 20 characters";
}
else if (!preg_match("/^[a-zA-Z0-9_]*$/",$username)) {
$error = "Only alphanumeric characters and underscores allowed in username";
}
else if(strlen($password)<6){
$error = "Password too short. Minimum 6 characters";
}
else if(strlen($password)>20){
$error = "Password too long. Maximum 20 characters";
}
else if($password!==$cpassword){
$error = "Passwords do not match";
}
else if($name==""){
$error = "Please fill out your name";
}
else if(strlen($name)>30){
$error = "Name too long. Maximum 30 characters";
}
else if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$error = "Only letters and spaces allowed in Name";
}
else if($rollno==""){
$error = "Please enter your roll no";
}
else{
if(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
$error = "Invalid Email!";
}
else if(!preg_match('/^[0-9]{10}$/',$phno)){
$error = "Invalid Phone number! Don't mention +91 at the beginning.";
}
else{
//Validation was fine..
}
}
require_once("judge/dbconfig.php");
$sql = "select * from users where username='".$username."'";
$res = mysqli_query($conn,$sql);
if(mysqli_num_rows($res)>0){
$error = "Username already exists";
}
$password = md5($password);
$ip = $_SERVER["REMOTE_ADDR"];
if($error==""){
$sql = "insert into users(username,password,name,rollno,email,phno,ip) values ('$username','$password','$name','$rollno','$email','$phno','$ip')";
mysqli_query($conn,$sql);
session_start();
$_SESSION["user"] = $username;
$_SESSION["name"] = $name;
$_SESSION["rollno"] = $rollno;
header('location:judge/index.php');
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="judge/css/bootstrap.min.css" rel="stylesheet">
<link href="judge/css/portfolio-item.css" rel="stylesheet">
<style>
.register{ height:<?php if($error!="") echo "340"; else echo "320"; ?>px;width:220px;margin:auto;border:1px #CCC solid;padding:10px;}
.register input { padding:5px;margin:5px}
</style>
<title>Tansy OJ</title>
</head>
<body>
<div class="container">
<div class="col-md-4">
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">User registration</div>
<div class="panel-body">
<img src="loadra.png">
<?php if($error!="") echo "<div style=\"color:red;width:98%;height:auto;border-radius:10px;border-style:solid;border-color:red;border-width:2px;background-color:#EEAFB0;padding:10px;margin-left:1%;margin-right:1%;margin-top:2%;margin-bottom:2%;text-align:center;vertical-align:middle;font-weight:normal\">".$error."</div>"; ?>
<form method="post" action="">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" placeholder="Username" id="username" name="username" value="<?php echo htmlspecialchars($_POST["username"]); ?>" class="form-control" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" placeholder="Password" id="password" name="password" value="<?php echo htmlspecialchars($_POST["password"]); ?>" class="form-control" required>
</div>
<div class="form-group">
<label for="cpassword">Confirm Password:</label>
<input type="password" placeholder="Confirm Password" id="cpassword" value="<?php echo htmlspecialchars($_POST["cpassword"]); ?>" name="cpassword" class="form-control" required>
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" placeholder="Name" id="name" name="name" value="<?php echo htmlspecialchars($_POST["name"]); ?>" class="form-control" required>
</div>
<div class="form-group">
<label for="rollno">Roll number (Ex: BE/10010/12):</label>
<input type="text" placeholder="Roll number" id="rollno" name="rollno" value="<?php echo htmlspecialchars($_POST["rollno"]); ?>" class="form-control" required>
</div>
<div class="form-group">
<label for="email">Email ID (Ex: [email protected]):</label>
<input type="text" placeholder="Email ID" id="email" name="email" value="<?php echo htmlspecialchars($_POST["email"]); ?>" class="form-control" required>
</div>
<div class="form-group">
<label for="phno">Phone no: (Ex: 9898989898):</label>
<input type="number" placeholder="Phone number" id="phno" name="phno" value="<?php echo $_POST["phno"]; ?>" class="form-control" required>
</div>
<input type="submit" value="Sign up" class="btn btn-primary"><br /><br />
<a href="index.php">Login here </a>
</div>
</form>
</div>
</div>
</div>
<script src="judge/js/jquery.js"></script>
<script src="judeg/js/bootstrap.min.js"></script>
</body>
</html>