-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommons.php
35 lines (31 loc) · 918 Bytes
/
commons.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
<?php
class Commons {
function checkUserSession($pathRedir = null)
{
if(session_id() == '') {
session_start();
}
// ensure already signed in
if ( !$_SESSION['loggedin'] ) {
if(is_null($pathRedir))
{
//$path = $_SERVER['HTTP_HOST'];
//echo "BEFORE = ".$path.'<BR>';
$pieces = explode("/", $_SERVER["REQUEST_URI"]);
$count_pieces = count($pieces);
unset($pieces[$count_pieces-1]);
$path = implode("/",$pieces);
//echo "AFTER = ".$path.'<BR>';
header('Location: '.$path.'/login.php' );
}
else{
header('Location: '.$pathRedir.'/login.php' );
}
}
}
function logout() {
session_destroy();
header('Location: login.php' );
}
}
?>