Example #1
0
 /**
  * Detects if there is concurrent session (i.e. another user logged in with the same current user credentials),
  * If so, then logout.
  */
 public static function checkSessionConcurrency()
 {
     if (Session::userIsLoggedIn()) {
         if (Session::isConcurrentSessionExists()) {
             \Huge\Model\LoginModel::logout();
             Redirect::home();
             Application::stop();
         }
     }
 }
 public function getConnection()
 {
     if (!$this->database) {
         /**
          * Check DB connection in try/catch block. Also when PDO is not constructed properly,
          * prevent to exposing database host, username and password in plain text as:
          * PDO->__construct('mysql:host=127....', 'root', '12345678', Array)
          * by throwing custom error message
          */
         try {
             $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);
             $this->database = new PDO(Config::get('DB_TYPE') . ':host=' . Config::get('DB_HOST') . ';dbname=' . Config::get('DB_NAME') . ';port=' . Config::get('DB_PORT') . ';charset=' . Config::get('DB_CHARSET'), Config::get('DB_USER'), Config::get('DB_PASS'), $options);
         } catch (\PDOException $e) {
             // Echo custom message. Echo error code gives you some info.
             echo 'Database connection can not be estabilished. Please try again later.' . '<br>';
             echo 'Error code: ' . $e->getCode();
             // Stop application :(
             // No connection, reached limit connections etc. so no point to keep it running
             Application::stop();
         }
     }
     return $this->database;
 }
Example #3
0
<?php

define('ROOT', realpath(__DIR__ . '/..'));
define('BASE', dirname($_SERVER['PHP_SELF']) != '/' ? dirname($_SERVER['PHP_SELF']) : '');
// Load vendor libraries
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    include_once __DIR__ . '/../vendor/autoload.php';
}
include_once __DIR__ . '/loader.php';
// load application libraries
__include_dir(__DIR__ . '/../libraries');
// Application configuration
__include_dir(__DIR__ . '/../config');
// Session
Session::start(Environment::get('WebSeed.session_string'));
// Kernel model
if (defined('KERNEL_MODE')) {
    Application::stop();
    require_once __DIR__ . '/kernel.php';
}
// Application init
Application::init();
// load custom configuration
require_once __DIR__ . '/../init.php';