-
Notifications
You must be signed in to change notification settings - Fork 9
/
register.php
64 lines (50 loc) · 1.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
<?php
session_start();
$username=$_POST["username"];
$fname=$_POST["fname"];
$lname=$_POST["lname"];
$gender=$_POST["gender"];
$email=$_POST["email"];
$phone=$_POST["contact"];
$deptid=$_POST["department"];
$password=$_POST["password"];
$password1=trim($password);
$hash=hash('sha256', $password1);
$_SESSION["sess_lastname"]=$_POST["lastname"];
$mysqli = new mysqli("localhost","root","root","project");
if ($mysqli->connect_error){
die('Could not connect to database!');
}
$salt = createSalt();
function createSalt()
{
$text = md5(uniqid(rand(), TRUE));
return substr($text, 0, 3);
}
$hash1 = hash('sha256', $salt . $hash);
$result = mysqli_query($conn,"SELECT net_id from user_login where net_id = '$username'");
if (mysqli_num_rows($result) == 0) {
$result1 = mysqli_query($conn,"SELECT phone from users where email = '$email'");
echo $email;
if (mysqli_num_rows($result1) == 0) {
echo "About to insert";
$sql="INSERT INTO users (net_id, firstname, lastname,email,d_id,u_role,phone,gender) VALUES
('$username', '$fname', '$lname', '$email','$deptid', 'student','$phone', '$gender')";
$sql1="INSERT INTO user_login (net_id, password,salt_value) VALUES
('$username', '$hash1', '$salt')";
if(!mysqli_query($mysqli,$sql) || !mysqli_query($mysqli,$sql1)){
header('Location: index.html');
} else {
session_regenerate_id();
$_SESSION['sess_username'] = $username;
session_write_close();
header('Location: user/welcome.html');
}
} else {
header('Location: index.html');
}
} else {
header('Location: index.html');
}
mysqli_close($mysqli);
?>