-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
86 lines (79 loc) · 2.59 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
<?php
include 'core/init.php';
logged_in_redirect();
include 'includes/overall/overall_header.php';
if (empty($_POST) === false) {
$required_fields = array('user_name', 'password', 'password_again', 'first_name', 'email'); //add last name & other fields here later, not incl for testing
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true){
$errors[] = 'Fields marked with an asterisk are required.';
break 1;
}
}
if (empty($errors) === true) {
if(user_exists($_POST['username']) === true) {
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces.';
}
if (strlen($_POST['password']) <= 7) {
$errors[] = 'Your password must be at least 8 characters.';
}
if (strlen($_POST['password']) >= 25) {
$errors[] = 'Your password must be less than 25 characters.';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your passwords do not match.';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true) {
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.';
}
}
}
?>
<h1>Register</h1>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
echo 'You have been registered successfully';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'email_code' => md5($_POST['username'] + microtime())
);
register_user($register_data);
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=register.php?success">';
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action="" method="post">
<ul>
<li>Username*:<br>
<input type="text" name="username"> </li>
<li>Password*:<br>
<input type="password" name="password"></li>
<li>Confirm Password*:<br>
<input type="password" name="password_again"></li>
<li>First Name*:<br>
<input type="text" name="first_name"></li>
<li>Last Name:<br>
<input type="text" name="last_name"></li>
<li>Email Address*:<br>
<input type="text" name="email"></li>
<li>
<input type="submit" value="Register"></li>
</ul>
</form>
<?php }
include 'includes/overall/overall_footer.php';
?>