PHP Classes

File: Example.php

Recommend this page to a friend!
  Classes of Ramesh Narayan Jangid   Session Handlers Collection   Example.php   Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Session Handlers Collection
Store PHP sessions in different types of storage
Author: By
Last change: Refactoring
Date: Yesterday
Size: 654 bytes
 

Contents

Class file image Download
<?php
include __DIR__ . '/SessionHandlers/Session.php';

// Initialise Session Handler
Session::initSessionHandler('File');
// Session::initSessionHandler('MySql');
// Session::initSessionHandler('Redis');
// Session::initSessionHandler('Memcached');

// Start session in readonly mode
// Use when user is already logged in and we need to authorise the client cookie.
Session::start_readonly();

// Auth Check
if (!isset($_SESSION) || !isset($_SESSION['id'])) {
    die(
'Unauthorised');
}

// Start session in normal (read/write) mode.
// Use once client is authorised and want to make changes in $_SESSION
Session::start_rw_mode();
$_SESSION['id'] = 1;