I'm trying to use Laravels authentication with a number of simple HTML/Javascript applications.
The way I think it would ideally work is this:
- The user visits the simple HTML application
- The simple HTML application includes a PHP file which checks if a user is authenticated. If this is not the case the user is sent to the Laravel application to login, if the user is logged in he can simply use the application.
- The user logs in through Laravel and is redirected back to the HTML application where this process will start over again.
The problem I have is checking whether a user is logged in the PHP script. Laravels session is not available there (and sharing it through session_start() and $_SESSION["auth"] = true will only add the variable to Laravels version of the native PHP session).
These are the settings I have in app/config/session.php
return array(
'driver' => 'native',
'lifetime' => 120,
'files' => storage_path().'/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => array(2, 100),
'cookie' => 'laravel_session',
'path' => null,
'domain' => null,
);
I've changed the path to null because I want to use the session on the entire domain.
My included PHP script is very simple and looks like this:
session_start();
if($_SESSION['authenticated']){
echo "logged_in";
} else {
header("Location: laravel/login/url");
}
You might wonder why I don't just include the application in Laravels framework, it's because there are about 100 different versions of this simple HTML application scattered over 10 domain names, at the moment every domain name has it's own (very old and insecure) login script (which is copied every time a new domain gets made). Therefor I want to centralize this with one database and one management system using Laravel.
Hopefully someone here knows how to fix this problem or work around it (maybe I should try to use Laravels session package in my PHP script?).