Support the ongoing development of Laravel.io →
Authentication Session
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

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();
}
Last updated 2 years ago.
0

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();
}
Last updated 2 years ago.
0

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

Last updated 9 years ago.
0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

kudoslabs kudoslabs Joined 7 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.