-
-
Save hassanuos/c9dab8f9959b8f3775f7bb7f692ce699 to your computer and use it in GitHub Desktop.
Get current Laravel active session from outside laravel instance. Laravel 5.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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