-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
83 lines (70 loc) · 1.86 KB
/
functions.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
<?php
ob_start();
$errors = array();
function protect() {
// if no Session and Cookie is found - redirect to login
if( !isset( $_SESSION['user'] ) && !isset( $_COOKIE['user'] ) ) {
header( "Location: index.php" );
exit();
}
}
function protectAdmin() {
// if no Session and Cookie is found - redirect to login
if( !isset( $_SESSION['admin'] ) && !isset( $_COOKIE['admin'] ) ) {
header( "Location: admin-login.php" );
exit();
}
}
/**
* "encrypt" passwords.
*
* @param [type] $pass
* @return [type] $pass
*/
function encrypt( $pass ) {
/* TODO: add Salt to .env && maybe add hash*/
$salt = "jhkl2jh8f8s898we8ewiouq48484b";
return sha1( $salt . $pass );
}
/**
* Count User
*
* @return int $userCount
*/
function user_counter() {
include 'database/connect.php';
// session_start();
$session = session_id();
$time = time();
$time_check = $time-600;
if( session_id() !== '' && $session !== '' ) {
$query = $con->prepare("SELECT * FROM user_online WHERE session = ?");
$query->bind_param("s", $session);
$query->execute();
$query->store_result();
$nm = $query->num_rows;
$query->close();
if( $nm == '0' ) {
$query = $con->prepare("INSERT INTO user_online (session, time) VALUES(?, ?)");
$query->bind_param("ss", $session, $time);
$query->execute();
$query->close();
} else {
$query = $con->prepare("UPDATE user_online SET time = ? WHERE session = ?");
$query->bind_param("ss", $time, $session);
$query->execute();
$query->close();
}
}
$query = $con->prepare("DELETE FROM user_online WHERE time < ?");
$query->bind_param("s", $time_check);
$query->execute();
$query->close();
$query = $con->prepare("SELECT count(*) FROM user_online");
$query->bind_result($userCount);
$query->execute();
$query->fetch();
$query->close();
return $userCount;
}
?>