-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
executable file
·47 lines (43 loc) · 1.36 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
<?php
session_start();
include "config.php";
include "private_functions.php";
include "functions.php";
if(isset($_SESSION['auth']) && $_SESSION['auth'] == 1) {
header('Location: '.$home.'index.php');
}
if(isset($_POST['username']) && isset($_POST['pw'])) {
if ( preg_match('/^[A-Za-z0-9]+$/', $_POST['username']) ) {
$pw = hash_pw($_POST['pw']);
$dbh = db_connect($MY_HOST, $MY_DB_PORT, $MY_DB, $DB_USER, $DB_PW);
$res = register($dbh, $_POST['username'],$pw);
if($res['status'] == 1) {
session_login($res['userID']);
header("Location: ".$home."index.php");
} else {
$err_msg = "Invalid register";
}
} else {
$err_msg = "Usernames can only consist of letters or numbers";
}
}
?>
<html>
<head>
<title>Register</title>
<?php html_output_head(); ?>
</head>
<body>
<div class="container">
<?php html_nav('register'); ?>
<div class="jumbotron">
<form class="form-signin" role="form" action='register.php' method='POST'>
<h2 class="form-signin-heading">Register</h2>
<h3 class="form-signin-heading"><?php echo $err_msg; ?> </h3>
<input type="text" class="form-control" name='username' placeholder="Username" required autofocus>
<input type="password" class="form-control" name='pw' placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
</form>
</div>
</body>
</html>