I also have had this problem. This needs to be resolved quickly as i need some way of accessing session data outside of laravel project
I'm having the same issue, although they are different subdomains (app.laravel.loc, site.wordpress.loc)
The wordpress session changes on each refresh although the laravel session is constant and works as expected.
Has there been any headway yet?
Hey guys, I had a very similar problem I had to solve. I have my Laravel instance setup in a subdirectory called "/shop". The root of the domain is controlled by a CMS (in this case ExpressionEngine). I am not sure this will work in a subdomain, but it's worth a shot. Anyway, I needed to check Auth::user()
to display specific pages in EE depending on the user's account type, and depending on the user being logged in. I couldn't find any working code examples on the internet, so I had to come up with something original that worked. Here what I came up with. I am testing using Laravel 4.2 and the below code example works perfectly for me. Obviously it's possible your Laravel file directories will differ, so be sure to use the correct file paths.
protected function getUser()
{
require $_SERVER['DOCUMENT_ROOT'].'/../bootstrap/autoload.php';
$app = require $_SERVER['DOCUMENT_ROOT'].'/../bootstrap/start.php';
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app->boot();
$app['session']->driver()->setId($id);
$app['session']->driver()->start();
return $app['auth']->driver()->user();
}
Thanks for this, I had to make it for Laravel 5, here is the code for those that are interested :
protected function getUser()
{
require $_SERVER['DOCUMENT_ROOT'].'/../bootstrap/autoload.php';
$app = require $_SERVER['DOCUMENT_ROOT'].'/../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']->driver()->user();
}
I've just found an other solution: using the following code you can boot into Laravel using the real Laravel session, so you can actually use Auth::check() for authorization and you don't even have to use the native $_SESSION.
See: gist.github.com/frzsombor/ddd0e11f93885060ef35
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community