Reputation: 863
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?
Upvotes: 1
Views: 924
Reputation: 12038
You'll have to save your value in the session or in a cookie. Try this:
$_SESSION['currFolder'] = dirname($_SERVER['PHP_SELF']);
Then you can retrieve it with:
$currFolder = $_SESSION['currFolder'];
Of course make sure you have called session_start() before trying to use the $_SESSION variable.
Upvotes: 1