Skip to content

Instantly share code, notes, and snippets.

@hassanuos
Forked from jcbagtas/auth.php
Created June 21, 2021 13:18
Show Gist options
  • Save hassanuos/c9dab8f9959b8f3775f7bb7f692ce699 to your computer and use it in GitHub Desktop.
Save hassanuos/c9dab8f9959b8f3775f7bb7f692ce699 to your computer and use it in GitHub Desktop.
Get current Laravel active session from outside laravel instance. Laravel 5.2
<?php
/**
* Get current Laravel active session from outside laravel instance.
* Tested Laravel 5.2
*
*
*/
function getLaravelUser()
{
require __DIR__ . '\path\to\bootstrap\autoload.php';
require __DIR__ . '\path\to\bootstrap\app.php';
$app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();
return $app['auth']->user();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment