-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateAccount_handler.php
More file actions
73 lines (58 loc) · 1.55 KB
/
createAccount_handler.php
File metadata and controls
73 lines (58 loc) · 1.55 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
<?php
session_start();
ini_set('display_erroes',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
$invalid = false;
require_once('Dao.php');
$username = $email = $password = "";
$dao= new Dao();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["username"])) {
$nameErr = "Name is required";
$_SESSION['nameErr']=$nameErr;
$invalid=true;
}
else{
$username = test_input($_POST["username"]);
$_SESSION['preset_username'] = $username;
if (!preg_match("/^[a-zA-Z ]*$/",$username))
{
$nameErr = "Only letters and white space allowed\n";
$_SESSION['nameErr']=$nameErr;
$invalid=true;
}
}
$email = test_input($_POST["email"]);
//email info validation
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email format\n";
$_SESSION['emailErr']=$emailErr;
$invalid=true;
}else{
$_SESSION['preset_email']=$email;
}
if (empty($_POST["password"])) {
$passwordErr = "Password is required";
$_SESSION['passwordErr']=$passwordErr;
$invalid=true;
}
else {
$password = test_input($_POST["password"]);
}
}
//sanitization of the input information
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if($invalid==true){
header("Location:createAccount.php");
}else{
$dao->addUser($email,$password,$username);
header("Location:login.php");
}
?>