Skip to content

Instantly share code, notes, and snippets.

@3onyc
Created January 15, 2014 10:39
Show Gist options
  • Save 3onyc/8434142 to your computer and use it in GitHub Desktop.
Save 3onyc/8434142 to your computer and use it in GitHub Desktop.
Getting the Laravel session in a separate PHP file, honours session settings in config Laravel config.
<?php
require_once '/path/to/laravel/bootstrap/autoload.php';
// Initialize the app
$app = require '/path/to/laravel/bootstrap/start.php';
$request = $app['request'];
// Decrypt the cookies
$cookieGuard = new Guard($app, $app['encrypter']);
$cookieGuard->handle($request);
// Initialize the session
$session = $app['session.store'];
$session->setRequestOnHandler($request);
$session->setId($request->cookies->get($session->getName()));
$session->start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment