-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogLanding.php
More file actions
70 lines (62 loc) · 2.15 KB
/
LogLanding.php
File metadata and controls
70 lines (62 loc) · 2.15 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
<?php
header('Content-Type: application/json');
require __DIR__ . '/Credentials.php';
require __DIR__ . '/GetTargetUrl.php';
// Connect to the database
$Conn = new mysqli($Servername, $Username, $Password, $Dbname);
if ($Conn->connect_error) {
die("Database connection failed: " . $Conn->connect_error);
}
// Set $DateTime_Landing
$Now = new DateTimeImmutable("now", new DateTimeZone('Europe/London'));
$DateTime_Landing = $Now->format('Y-m-d\TH:i:s');
// Preallocate the result
$Result = array();
// Unpack the inputs
$Input = json_decode(file_get_contents('php://input'), true);
$PoolId = $Input['PoolId'];
$SubjectId = $Input['SubjectId'];
// Sanitize the inputs
$PoolId = mysqli_real_escape_string($Conn, $PoolId);
$SubjectId = mysqli_real_escape_string($Conn, $SubjectId);
// Query the Register to see if there is a match
// Set $Virgin and $State
// Reset $PoolId if available
$Sql00 = "SELECT * FROM Register WHERE SubjectId = '$SubjectId'";
$QueryRes00 = mysqli_query($Conn, $Sql00);
if ($QueryRes00 === false) {
$Conn->close();
die("Query Sql00 failed to execute successfully!");
} else {
$Virgin = true;
while ($Row = mysqli_fetch_assoc($QueryRes00)) {
$Virgin = false;
$PoolId = $Row["PoolId"]; // Redefine as it may be null;
$State = $Row["State"];
}
}
// Branch dependent on whether they have been here before...
if ($Virgin) {
// They HAVE been here before
$Sql01 = "INSERT INTO Register
(PoolId, SubjectId, State, DateTime_Landing)
VALUES ('$PoolId', '$SubjectId', 0,'$DateTime_Landing')";
if ($Conn->query($Sql01) === false) {
$Conn->close();
die('Query Sql01 failed to execute successfully!');
}
} else {
// They have NOT been here before
$Sql02 = "INSERT INTO Relandings
(PoolId, SubjectId, State, DateTime_Reland)
VALUES ('$PoolId', '$SubjectId', $State, '$DateTime_Landing')";
if ($Conn->query($Sql02) === false) {
$Conn->close();
die('Query Sql02 failed to execute successfully!');
}
}
// Get TargetUrl and return
$Url = GetTargetUrl($Conn, $SubjectId);
$Result['TargetUrl'] = $Url;
$Conn->close();
echo json_encode($Result);