-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_handleSignup.php
63 lines (56 loc) · 2.43 KB
/
_handleSignup.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
<?php
$showError="false";
$showAlert=false;
if($_SERVER["REQUEST_METHOD"]=="POST"){
include 'db_connect.php';
$useremail=$_POST['useremail'];
$useremail=str_replace("<","<","$useremail");
$useremail=str_replace(">",">","$useremail");
$useremail=str_replace('"',""","$useremail");
$useremail=str_replace("'","'","$useremail");
$pass=$_POST['signupPassword'];
$pass=str_replace("<","<","$pass");
$pass=str_replace(">",">","$pass");
$pass=str_replace('"',""","$pass");
$pass=str_replace("'","'","$pass");
$username = $_POST['username'];
$username = str_replace("<", "<", $username);
$username = str_replace(">", ">", $username);
$username = str_replace('"', """, $username);
$username = str_replace("'", "'", $username);
$cpass=$_POST['signupcPassword'];
// Get the user's email ID from the input form
// Check if the email ID is of the form "@somaiya.edu"
if (!preg_match('/^[a-zA-Z0-9._%+-]+@somaiya\.edu$/', $useremail)) {
// Redirect the user to an error page
$showError="Invalid email id! Use institute account only";
header("Location: /collage_forum/index.php?signupsuccess=false&error=true");
}
else {
//check whether this email exists
$existsql="select * from `users` where user_email='$useremail'";
$result=mysqli_query($conn,$existsql);
$numRows=mysqli_num_rows($result);
if($numRows>0){
$showError="Email already in use";
header("Location: /collage_forum/index.php?signupsuccess=false&emailused=true");
}
else{
if($pass==$cpass){
$hash=password_hash($pass,PASSWORD_DEFAULT);
$sql="INSERT INTO `users` (`user_email`,`user_name`, `user_pass`, `timestamp`) VALUES ('$useremail','$username', '$hash', current_timestamp())";
$result=mysqli_query($conn,$sql);
if($result==true){
$showAlert=true;
echo $showAlert;
header("Location: /collage_forum/index.php?signupsuccess=true&error=false");
}
}
else{
$showError="Password do not match";
header("Location: /collage_forum/index.php?signupsuccess=false&passerror=true");
}
}
}
}
?>