Skip to content

Instantly share code, notes, and snippets.

@nikosv
Forked from frzsombor/gist:ddd0e11f93885060ef35
Last active May 6, 2021 08:09
Show Gist options
  • Save nikosv/296f0bc16cbbae2fec98 to your computer and use it in GitHub Desktop.
Save nikosv/296f0bc16cbbae2fec98 to your computer and use it in GitHub Desktop.
Share Laravel 5 session and check authentication from external projects
<?php
/*
|--------------------------------------------------------------------------
| Sharing Laravel's session and checking authentication
|--------------------------------------------------------------------------
|
| Use the following code in any CMS (WordPress, Joomla, etc), filemanager (CKFinder,
| KCFinder, simogeos's Filemanager, etc), or any other non-Laravel project to boot into
| the Laravel framework, with session support, and check if the user is authenticated.
|
| The following code is tested with Laravel 5
|
| Last update: 2015-03-17
|
*/
require '/path/to/laravel/bootstrap/autoload.php';
$app = require_once '/path/to/laravel/bootstrap/app.php';
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$isAuthorized = Auth::check();
@octoxan
Copy link

octoxan commented Jan 23, 2017

Not sure why but this is only working for me on the base wordpress url. On example.com I can get the full Authorized Laravel user but if I go to example.com/directory/ it returns null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment