-
Notifications
You must be signed in to change notification settings - Fork 1
/
connect.php
98 lines (78 loc) · 2.77 KB
/
connect.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
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
<?php
/*
Tombola
Il classico gioco natalizio online.
Copyright (C) 2020 Vincenzo Padula
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
session_start();
// Credenziali database
$host = 'localhost';
$user = 'vincenzopadula';
$database = 'my_vincenzopadula';
$psw = '';
// Password di amministratore
define("ADMIN_PW", "abcd");
define("PREFIX", "tombola_k_");
$dbh = mysqli_connect($host, $user, $psw, $database);
if(!$dbh) {
die("Errore di connessione al database.");
}
// Session
if(isset($_SESSION["idserver"])) $idserver = $_SESSION["idserver"];
if(isset($_SESSION["idutente"])) $idutente = $_SESSION["idutente"];
/* Cancella le partite abbandonate */
mysqli_query($dbh, "update ".PREFIX."server set offlimits = 1 where offlimits is false and datediff(now(), data) > 2;");
function redirect($link) {
header("Location: $link");
die();
}
function inviaMessaggio($messaggio, $link, $content = null) {
global $dbh;
$data = urlencode(json_encode($content));
$messaggio = rimuovi_apici($messaggio);
$_SESSION['messaggio'] = array($messaggio, $data);
mysqli_close($dbh);
redirect($link);
}
function rimuovi_apici($data) {
$data = str_replace("'", "'", $data);
$data = str_replace('"', """, $data);
return $data;
}
function checkOnlyNumbers($number = null) {
if(is_numeric($number) && strpos($number, ".") == false && $number > 0) return true;
return false;
}
function is_a_username($username = null) {
if($username == null || $username == "") return false;
return preg_match("/^[a-zA-Z0-9_.-]{2,20}$/", $username);
}
function adminLogin($msg = "Password di amministratore") {
// La password è stata inserita?
if(! isset($_POST['admin_pw'])) {
echo "<p style='padding-top:20vh;'>$msg</p>\n".
"<form action='#' method='post'>\n".
"<input type='password' name='admin_pw' placeholder='Inserire la password' /><br>\n".
"<button type='button' onclick='window.location.href=\"./\";'>Home</button>\n".
"<button type='submit'>Accedi</button>\n".
"</form>\n";
return false;
}
if($_POST['admin_pw'] != ADMIN_PW) {
echo "<p>Password errata.</p>\n".
"<button onclick='window.location.href=\"./\";'>Home</button>\n";
return false;
}
return true;
}
?>