forked from AyatsujiTsukasa/Ant-Planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleSignIn.php
39 lines (39 loc) · 1.28 KB
/
googleSignIn.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
<?php
$servername = "localhost";
$name = "antinc";
$password = "AntInc_AntInc123";
$dbname = "Ant_Planner";
$conn = mysqli_connect($servername, $name, $password, $dbname);
if (!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
if(!$_POST) {
die("This file cannot be accessed directly!");
}
$username = $_POST['username'];
$email = $_POST['email'];
$EmailCheckQuery = "select * from Users where email='".$email."'";
$EmailResult = $conn->query($EmailCheckQuery);
if($EmailResult->num_rows === 0){
// If email does not match to any record, then register first
$password = "google";
$sql = "insert into Users (username, email, password, friends) values('".$username."','".$email."','".$password."','')";
if($conn->query($sql) === true) {
$EmailCheckQuery = "select * from Users where email='".$email."'";
$EmailResult = $conn->query($EmailCheckQuery);
} else {
exit("Connection error. Please try again later.");
}
}
// Log in
$row = mysqli_fetch_array($EmailResult);
$id = $row['id'];
$password = $row['password'];
$time = 300;
setcookie("username", $username, time()+$time, "/");
setcookie("ownerId", $id, time()+$time, "/");
setcookie("password", $password, time()+$time, "/");
echo "<script>
window.location = 'userhome.html';
</script>";
?>