-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
31 lines (30 loc) · 960 Bytes
/
init.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
<?php
// require_once 'debug.php';
require_once 'config.php';
//@Nair : Meant to be inserted as require in the top of everyfile except index.
$conn = new mysqli ($db_hostname , $db_username , $db_password , $db_databasename);
session_start();
if (!isset($_SESSION['user'])) {
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '';
header("Location: http://$host$uri/$extra");
}
if (!isset($_SESSION['admin'])) {
$query = $conn->prepare("SELECT `id` FROM `Admins` WHERE `user_id` = (SELECT `id` FROM `Users` WHERE `user_id` = ? LIMIT 1)");
$query->bind_param("s" , $_SESSION['user']);
$query->execute();
$query->bind_result($id);
if ($id) {
$_SESSION['admin'] = $_SESSION['user'];
}
$query->close();
}
if (isset($_REQUEST['logout'])) {
session_destroy();
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '';
header("Location: http://$host$uri/$extra");
}
?>