-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
53 lines (46 loc) · 1.4 KB
/
index.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
<?php session_start(); ?>
<?php require('./utils/array_utils.php'); ?>
<?php require('./utils/db_connector.php'); ?>
<?php
// check user session
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("Location: login.php");
}
// check timeout session
$login_session_duration = 60 * 10;
$current_time = time();
$loggedint_time = $_SESSION["loggedin_time"];
if($current_time - $loggedint_time > $login_session_duration){
header("Location: logout.php");
exit(0);
}
// check 'action' from get params
if(!array_key_exists("action", $_GET)){
header("Location: index.php?action=home");
exit(0);
}
// update time session
$_SESSION["loggedin_time"] = time();
// get action value from action key in $_GET
$action = $_GET['action'];
?>
<?php require('./partials/header.php'); ?>
<?php
// filter only php extension
$filter_file_name = array_filter(scandir("./"), "filter_php_file");
$page_php_path = "{$action}.php";
if(in_array($page_php_path, $filter_file_name, true))
include($page_php_path);
else
include("404.php");
// include essentails scripts
require("./partials/scripts.php");
// include script control withit page
$page_script_path = "scripts/{$action}.js";
if(file_exists($page_script_path)){
echo "<script>";
include($page_script_path);
echo "</script>";
}
?>
<?php require("./partials/footer.php"); ?>