forked from CSS-Tricks/Chat2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjumpin.php
70 lines (45 loc) · 1.48 KB
/
jumpin.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
session_start();
require_once("dbcon.php");
if (isAjax()) {
$data = array();
$username = cleanInput($_POST['userid']);
if (checkVar($username)) {
$getUsers = "SELECT *
FROM chat_users
WHERE username = '$username'";
if (!hasData($getUsers)) {
$data['result'] = "<div class='message success'>Great! You found a username not in use</div>";
$data['inuse'] = "notinuse";
} else {
$data['result'] = "<div class='message warning'>That username is already in use. (Usernames take 2 minutes without use to expire)</div>";
$data['inuse'] = "inuse";
}
echo json_encode($data);
}
} else {
$username = cleanInput($_POST['userid']);
if (checkVar($username)) {
$getUsers = "SELECT *
FROM chat_users
WHERE username = '$username'";
if (!hasData($getUsers)) {
$now = time();
$postUsers = "INSERT INTO `chat_users` (
`id` ,
`username` ,
`status` ,
`time_mod`
)
VALUES (
NULL , '$username', '1', '$now'
)";
mysql_query($postUsers);
$_SESSION['userid'] = $username;
header('Location: ./chatrooms.php');
} else {
header('Location: .?error=1&user='.$username);
}
}
}
?>