-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
109 lines (85 loc) · 3.02 KB
/
functions.php
File metadata and controls
109 lines (85 loc) · 3.02 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/*
* Copyright (c) 2011 Matteo Bernardini
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once("config.php");
//in caso di manutenzione:
if ($maint && $_COOKIE['maint'] != $maintValue && !($beta && $_COOKIE['beta'] == $betaValue)) {
require("./include/maintenance.html");
exit();
}
//Escludere IE dalla Beta
if ($noIE && $beta && $_COOKIE['beta'] == $betaValue && stripos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== false) {
require("./include/maintenance-msie.html");
exit();
}
function createForm(){
global $expireTime;
require("./include/login_view.php");
}
function createChat() {
require("./include/chat_view.php");
}
function createError() {
echo '<div class="error">Si è verificato un errore sconosciuto. Prova a ricaricare la pagina</div>';
}
//Define variables and cases
$timeToExpire = time() + (89 * 89 * 89 * 89);
if (isset($_POST['aut'])) {
$username = trim(htmlspecialchars($_POST['name'], ENT_QUOTES, "UTF-8"));
if ($_POST['remember']) {
setcookie("username", $username, $timeToExpire);
setcookie("remember", "1", $timeToExpire);
} else {
setcookie("username", $username);
setcookie("remember", "0", $timeToExpire);
}
setcookie("autologin", $_POST['autologin']=="on"?"1":"0", $timeToExpire);
header("Location: user.php?do=login");
exit();
}
if (isset($_GET['logout']) && $_COOKIE['logged'] == 1) {
header("Location: user.php?do=logout");
exit();
}
$nickname = trim(htmlspecialchars($_COOKIE['username'], ENT_QUOTES, "UTF-8", false));
function switchCases() {
global $nickname, $timeToExpire;
if (isset($_GET['invalid']))
createError();
elseif (isset($_GET['logout']) && isset($_GET['login'])) {
header("Location: ?login=1");
exit();
}
elseif ($_COOKIE['autologin'] && !empty($nickname) && ($_COOKIE['logged'] == 0 || empty($_COOKIE['logged']))) {
setcookie("username", $nickname, $timeToExpire);
setcookie("remember", "1", $timeToExpire);
setcookie("autologin", "1", $timeToExpire);
header("Location: user.php?do=login");
}
elseif (isset($_GET['logout']))
createForm();
elseif (empty($_COOKIE['username']) || $_COOKIE['logged'] == 0 || empty($_COOKIE['logged'])) {
header("Location: ?logout=1");
exit();
}
elseif (isset($_COOKIE['username']) && $_COOKIE['logged'] == 1 && isset($_GET['login']))
createChat();
else {
header('Location: ?login=1');
exit();
}
}
?>