I’ve a project, with various subdirs that make use of a functions.php file located in the project root folder
include "../functions.php";
The thing is that I need to save the current subdir path so on reloading the page, it will redirect me to the folder I was before, and not the root folder.
header('Location: '.$currFolder.'index.php');
To do so, I (try to) store it to a variable by calling a function in each subdir index.php file
$currFolder = dirname($_SERVER['PHP_SELF']); // returns "/root/subdir"
But for some reason, variable stays empty, so the header keeps redirecting me to root… What I’m doing wrong?
You’ll have to save your value in the session or in a cookie. Try this:
Then you can retrieve it with:
Of course make sure you have called session_start() before trying to use the $_SESSION variable.