PHP Classes

File: app/session.php

Recommend this page to a friend!
  Classes of Faris AL-Otabi   PHP Chat Application with API   app/session.php   Download  
File: app/session.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Chat Application with API
Exchange user messages on a page or using an API
Author: By
Last change:
Date: 6 months ago
Size: 948 bytes
 

Contents

Class file image Download
<?php
session_start
();
include_once
'config.php';
include_once
'src/Database.php';
include_once
'src/User.php';
include_once
'src/Auth.php';
include_once
'src/Utility.php';

ini_set("display_errors", 1);
error_reporting(E_ALL);

$utils = new Utility();
$db = new Database($config);
$user = new User($db);
$auth = new Auth($db);

$current_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

if (isset(
$_SESSION)) {
   
$username = isset($_SESSION['username']) ? $_SESSION['username'] : null;

    if (
$username != null) {
        if (isset(
$_SESSION['loggedin'])) {
           
$data = $user->getByUsername($username);
           
$_SESSION["is_admin"] = $data->is_admin;
        }
    }


    if (
strpos($current_url, "rooms.php")) {
        if (!(
$_SESSION['is_admin'])) {
           
$utils->redirect(('index.php'));
        }
    }

    if (!isset(
$_SESSION['loggedin'])) {
       
$utils->redirect("login.php");
    }
}

$page = 'session';