|| 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 4.2.11|
|| It may not work with Laravel 5|
|| Last update: 2015-01-09|
|$app = require_once '/path/to/laravel/bootstrap/start.php';|
|$request = $app['request'];|
|$client = (new \Stack\Builder)|
|->push('Illuminate\Session\Middleware', $app['session'], null);|
|$stack = $client->resolve($app);|
|$isAuthorized = Auth::check();|
All the time I tried integrating a filemanager (KCFinder, simogeo's Filemanager, etc), into a Laravel project, checking if the user is authenticated was always a problem. Reading a few Stackoverflow questions, and other forum/blog posts, it looks like from around 4.1.28, Application::boot() does not initialize sensitive session data anymore, so I had to create a solution to initialize the framework without actually calling Application::run().
Here are a few pages I've found about this issue:
stackoverflow.com: share session info with laravel and back
I've linked this Gist to all of the above pages, so we can discuss if my
Hope someone finds this useful!
It is really useful and works good.
For Laravel 5 try:
my Config.php file is :
but error in filemanager Page :
Undefined variable: lang
laravel 4.2 .
after some hour of study.
and then in the config.php
now, only authorized user can access the ckfinder, but outsider are being blocked.
Hi, I am using this way for getting csrf_token but problem is laravel boots up but the page gets break after booting laravel
my code is as follow:
I have login page in wordpress and from that page I want to post on Laravel with csrf_token.
Edit: I am using laravel 4.2
Edit: I thought I was using Laravel 4.2 but actually I am using Laravel 4.0.
It was causing the problem of stucking and breaking the page.
Solution: I created another start.php for wordpress called start_cms.php and commented the above method call in that.Now it works very well.
Any ideas on how to get this working in Laravel 5.3?
So far I've gotten here...
require $_SERVER['DOCUMENT_ROOT'].'/../rbpoarentals/bootstrap/autoload.php'; $app = require $_SERVER['DOCUMENT_ROOT'].'/../laravel/bootstrap/app.php'; $kernel = $app->make('Illuminate\Contracts\Http\Kernel'); $response = $kernel->handle( $request = Illuminate\Http\Request::capture());
And it works on the Wordpress home page (example.com/) but no any subdirectories like example.com/page/.
I var_dump'd the $response and can see that the $response is the 404 page. So I could fix this by adding every single Wordpress url to my Laravels routes file... but that is messy. Any idea how I could have it start the Laravel app from the index no matter what Wordpress url I am at?
The 404 page on Laravel doesn't have access to the session.
@octoxan I'm in the same boat. Curious if you ever solved the issue. The root path works fine, it's as though I need to allow the request to fall through all of laravel's routes and then be handled by wordpress. Along those lines I added the rollowing to the end of my web routes, which seems to be working(but I'm sure it has some sort of catch):
The solution above for 5.2 should still work. In 5.5+ you just need to change
<?php require '/path/to/laravel/vendor/autoload.php'; $app = require_once '/path/to/laravel/bootstrap/app.php'; $app->make('Illuminate\Contracts\Http\Kernel') ->handle(Illuminate\Http\Request::capture()); // An instance of the Laravel app should be now at your fingertip ;-) ... $isAuthorized = Auth::check();
I tried to use the code for getting laravel auth check in an external php file but it always returns null
this is my code
it always returns null
I managed to get mine to work properly in an external PHP file by manually starting the session before checking for auth data.
require '/path/to/bootstrap/autoload.php'; $app = require_once '/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']]); $session = $app['session']->driver(); $session->setId($id); $session->start(); $isAuthenticated = $app['auth']->check();
$app = require_once '/var/www/vhosts/xxx.xxx.com/bootstrap/app.php';
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$session = $app['session']->driver();
$isAuthenticated = $app['auth']->check();
I can get the laravel session data using above code to any PHP file.
@Developers-account Don't work mate. $app->make('Illuminate\Contracts\Http\Kernel') is throwing a fit with the following error. "Call to a member function make() on boolean"
I need to understand Laravel indepth.