This repository has been archived by the owner on Dec 23, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.php
56 lines (55 loc) · 1.55 KB
/
api.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
<?php
// Include config.php file
include 'config.php';
// Include functions.php file
include 'functions.php';
// Start a session if there isn't any
if (!isset($_SESSION)) {
session_start();
}
// Get User's IP address
$actIp = $_SERVER['REMOTE_ADDR'];
// This is a JSON file
header('Content-Type: application/json');
// If license is posted by GET...
if (isset($_GET['license'])) {
// Set $protocol to GET
$protocol = 'GET';
// Set $license to the license
$license = $_GET['license'];
// If license is posted by POST...
} elseif (isset($_POST['license'])) {
// Set $protocol to POST
$protocol = 'POST';
// Set $license to the license
$license = $_POST['license'];
// If license isn't posted
} else {
$license = 'NONE';
}
// Clean $license
$license = $mysqli->real_escape_string($license);
// SQL Query to check if license exists
$sql = "SELECT * FROM license_data WHERE purchase_code='$license'";
if (!$result = $mysqli->query($sql)) {
// Log info to database
$activityType = '1';
$activityTitle = 'Query execution error (api.php)';
updateActivity($activityType, $activityTitle);
exit();
}
if ($result->num_rows === 0) {
// Log info to database
$activityType = '2';
$activityTitle = 'Invalid license: '.$license;
updateActivity($activityType, $activityTitle);
exit();
}
// Make an array with all user data
$userdata = $result->fetch_assoc();
// Log info to database
$activityType = '3';
$activityTitle = 'Valid license: '.$license;
updateActivity($activityType, $activityTitle);
// Return the array
echo json_encode($userdata);