I have an application in Laravel and I need to check, from an external script, if a user is logged in or not and what it is. For this I use the following lines of code, to load Laravel:
require_once __DIR__.'/../../../vendor/autoload.php';
$app = require_once __DIR__.'/../../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());
/*if (Cookie::get(config('session.cookie')) != "") {
$id = Cookie::get(config('session.cookie'));
Session::driver()->setId($pericod);
Session::driver()->start();
}*/
$isAuthorized = Auth::check();
if(!$isAuthorized){
echo "NO AUTORIZADO";
exit();
}
With these lines I have access to any function of Laravel and in fact, the login check works correctly for GET
requests, but when it is a request POST
fails me, it is not able to recognize the login, from fact, I think he restarts the session because he is not able to recover the one that existed.
I have done a lot of tests and I think that it does not load or use certain parts of the Laravel, for example, it does not recognize the routes, it does not load the middlewares, etc ...
Use Laravel 5.7 updated today and this same code has come to work for me, I remember that in Laravel 5.4.
Any ideas of what may be failing?
thank you very much.