-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
75 lines (70 loc) · 1.8 KB
/
functions.php
File metadata and controls
75 lines (70 loc) · 1.8 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
75
<?php
// Replace with
function pusher_sync($data)
{
$app_id = 'your data here';
$key = 'your data here';
$secret = 'your data here';
//$pusher = new Pusher($key, $secret, $app_id);
//$pusher->trigger(loginCheck(), 'TODO', $data);
}
function login($user, $remember){
// All the autentication has happened, now we just need to make the session.
$ID = genRandomString() . uniqid('');
if ($remember == 'true')
{
// 10 years should be enough.
$time = time()+60*60*24*365*10;
}
else
{
$time = 0;
}
setcookie('ToDoSID', $ID, $time, '/', 'webbies.dk');
$userAgent = $_SERVER['HTTP_USER_AGENT'];
mysql_query("INSERT INTO notes_session (username, sid , userAgent) VALUES ('$user', '$ID', '$userAgent')") OR DIE(mysql_error());
return true;
}
function genRandomString() {
$length = 10;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
function loginCheck(){
$ID = $_COOKIE['ToDoSID'];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$result = mysql_query("SELECT * FROM notes_session WHERE sid='$ID'") OR DIE(mysql_error());
while($row = mysql_fetch_assoc($result)) //Lav en while der kører alle rækker igennem
{
$user = $row['username'];
$userAgent = $row['userAgent'];
}
if ($user)
{
return $user;
// Got tired of this after to many browser updates.
// If i uncomment it, it still works.
/*
if ($userAgent == $_SERVER['HTTP_USER_AGENT'])
{
return $user;
}
else
{
// Might be hacking attempt, deleting session.
// Few hackers / script kiddies think about this, so it works.
mysql_query("DELETE FROM notes_session WHERE sid='$ID'");
return false;
}*/
}
else
{
// No log in.
return false;
}
}
?>