Hi everyone!
I have, in my .htaccess, a “DirectoryIndex /boot.php” and a “ErrorDocument 404 /” line to redirect all my pages to boot.php.
boot.php
session_start();
require 'php/databases.php';
$req = $_SERVER['REQUEST_URI'];
$get = explode('/', $req);
$dir = '/' . $get[1] . '/';
$dir = __DIR__ . $dir;
$url = $dir . 'index.php';
ob_start();
if (is_file($url)) require $url;
else require 'error.php';
$content = ob_get_clean();
require 'page.php';
php/databases.php
$db = new PDO('mysql:host=localhost;dbname=***;charset=utf8', '***', '***');
$id = $_SESSION['id'];
if ($id) {
$req = $db->prepare('SELECT * FROM users WHERE id = ?');
$req->execute([$id]);
$user = $req->fetch();
extract($user);
}
… and page.php is basically the HTML part.
My problem is that the $_SESSION[‘id’] variable is functional on the pages that uses the “DirectoryIndex /boot.php” redirection (like “/” (home), “/register/” and “/login/”), but not on those that uses the “ErrorDocument 404 /” one (like “/profil/1/” because the “/profil/” folder does exist but not the “/profil/1/” one, which has to use the Error 404 redirection).
My website: Kruxy.fr
I’m French so there is a little French lesson if you want:
home → accueil
register → s’inscrire
log in → se connecter
username → pseudo
password → mot de passe
my profile → mon profil
log out → se déconnecter
Even if you can create an account, I created one for you to test if you want to:
Username: test
Password: password
You can see that it doesn’t work in the “/profil/” section by looking at the header which shows “Se connecter” and “S’inscrire” instead of “Mon profil” and “Se déconnecter”…
Please help me! How can I make the $_SESSION variable working on Error 404 pages? Keep in mind that it does function on certain pages.
Thank you! ✘