-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckuser.php
More file actions
28 lines (28 loc) · 962 Bytes
/
Copy pathcheckuser.php
File metadata and controls
28 lines (28 loc) · 962 Bytes
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
<?php
function CheckUser() {
global $username, $googleid, $uid, $conn;
if (empty($username))
die("User name required.");
if (empty($googleid)) {
$googleid = null;
$stmt = $conn->prepare('SELECT id, name, googleid FROM tg_user WHERE name=? and googleid IS NULL');
$stmt->execute(array($username));
} else {
$stmt = $conn->prepare('SELECT id, name, googleid FROM tg_user WHERE googleid=?');
$stmt->execute(array($googleid));
}
if (!($result=$stmt->fetch())) {
$stmt2 = $conn->prepare('INSERT INTO tg_user(name, googleid) VALUES(?,?)');
$stmt2->execute(array($username, $googleid));
$uid = $conn->lastInsertId();
} else {
$uid = $result['id'];
if ($result['name'] != $username) {
$stmt2 = $conn->prepare('UPDATE tg_user SET name=? WHERE id=?');
$stmt2->execute(array($username, $uid));
}
}
if (empty($uid))
die("Failed to get user id.");
}
?>