-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
63 lines (56 loc) · 1.46 KB
/
Copy pathuser.php
File metadata and controls
63 lines (56 loc) · 1.46 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
<?php
include_once "connect.php";
try {
switch($_SERVER['REQUEST_METHOD']) {
case 'GET':
if (!empty($_REQUEST['request']) && preg_match('/^([^\/]+)(?:\/([^\/]+)?)?$/', $_REQUEST['request'], $matches)) {
$idtype = $matches[1];
$id = $matches[2];
}
$sql = 'SELECT id, name, googleid FROM tg_user';
if (strlen($id) > 0)
$idSpecified = true;
else
$idSpecified = false;
if ($idtype == 'google') {
if ($idSpecified)
$sql .= ' WHERE googleid=?';
else
$sql .= ' WHERE googleid IS NOT NULL';
} else if ($idtype == 'name') {
if ($idSpecified)
$sql .= ' WHERE name=?';
} else {
http_response_code(404);
header('Content-Type: text/plain');
echo "$idtype not recognized.";
exit;
}
$stmt = $conn->prepare($sql);
if ($idSpecified)
$stmt->bindParam(1, $id);
$stmt->execute();
header('Content-Type: application/json');
$results = array();
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
array_push($results, $result);
}
if (!$idSpecified)
echo json_encode($results);
else
echo json_encode($results[0]);
break;
default:
http_response_code(405);
header('Allow: GET');
header('Content-Type: text/plain');
echo $_SERVER['REQUEST_METHOD'] . ' not allowed.';
break;
}
} catch (PDOException $e) {
http_response_code(500);
header('Content-Type: text/plain');
echo $e->getMessage();
}
$conn=null;
?>