-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetuid.php
More file actions
74 lines (70 loc) · 2.39 KB
/
getuid.php
File metadata and controls
74 lines (70 loc) · 2.39 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
71
72
73
74
<?php
//
// getuid.php -- generate a unique ID for a corona App
//
define("DB_DSN",'rmiracle_getuid');
define("DB_HOST",'localhost');
define("DB_USER",'rmiracle_getuid');
define("DB_PASS",'Star*Wars');
// Connecting, selecting database
// print("connecting to database\n");
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS)
or die('Could not connect: ' . mysql_error());
mysql_select_db(DB_DSN) or die('Could not select database');
if(isset($_GET)) {
if(isset($_GET["appid"])) {
//echo "logout";
$appid = $_GET["appid"];
$time = time();
$query = sprintf('INSERT INTO uids (appid,time) VALUES ("%s", %d)', mysql_real_escape_string($appid), $time);
$dbresult = mysql_query($query, $link);
if (!$dbresult) {
//echo "query failed";
$result = array();
$result["result"] = 403;
$result["message"] = mysql_error($link);
echo json_encode($result);
//mysql_free_result($dbresult);
exit;
}
$query = sprintf('SELECT id FROM uids WHERE appid="%s" AND time=%d', mysql_real_escape_string($appid), $time);
$dbresult = mysql_query($query, $link);
if (!$dbresult) {
//echo "query failed";
$result = array();
$result["result"] = 403;
$result["message"] = mysql_error($link);
echo json_encode($result);
//mysql_free_result($dbresult);
exit;
}
$row = mysql_fetch_row($dbresult);
$id = $row[0];
$uid = base64_encode(sprintf("%s%d",$appid,$id));
mysql_free_result($dbresult);
$query = sprintf('UPDATE uids SET uid="%s" WHERE id=%d',$uid,$id);
$dbresult = mysql_query($query,$link);
if (!$dbresult) {
//echo "query failed";
$result = array();
$result["result"] = 403;
$result["message"] = mysql_error($link);
echo json_encode($result);
//mysql_free_result($dbresult);
exit;
}
$result = array();
$result["result"] = 200;
$result["message"] = "Success";
$result["uid"] = $uid;
echo json_encode($result);
} else {
$result = array();
$result["result"] = 400;
$result["message"] = "Bad Request";
echo json_encode($result);
}
}
//echo "exiting";
exit;
?>