Forum Moderators: coopster
<edit>
forgot stating that the problem was when the original file passed a POST value to other files and then going back to that original file from other locations.
</edit.
In other words, if the session value for 'dir' is "dir1" and on a page I use a form to post a new value of "dir2", your script will see that $_SESSION is not empty and will ignore the post value.
A few things in addition to tunring around the priority of evaluation.
1. you test for
$dir=$_SESSION['dir'];
This is redundant and will give an undefined variable notice if the session var is undefined.
2. You test for
if ($_SESSION['dir'] == "")
Again, this will give an undefined variable notice. Better to use isset() or empty()
I think this will do what you seek
$dir_prefix = "/path/to/dir/passed/by/post/or/session/with/trailing/slash/";
if (!empty($_POST['dir']) && is_dir($dir_prefix . $_POST['dir']))
{
$dir= (empty($_POST['dir'))? '' : $_POST['dir'];
$_SESSION['dir'] = $dir;
}
elseif (!empty($_SESSION['dir']) && is_dir($dir_prefix . $_SESSION['dir']))
{
$dir= (empty($_SESSION['dir'))? '' : $_SESSION['dir'];
}
else
{
$dir = '';
}
However as strange as it seems my wrong/OK solution did the trick?
I will rather use your way
actually a very good work around my problem.
it is a great solution but it brings me a headache thinking about: How built a script that at first uses POST to make its job (When initiated) that passes that POST as a SESSION but when coming back to that very first script can only rely on SESSION and not on POST for that values is passed around via SESSION and not POST?
I know why my version works, I should have mentioned that if the file is accessed it is because a dir is submitted, so it’s impossible to access that file without a dir value passed. Another word submitting a dir calls for the file and pass the value
It actually is the only way to get to that file.
The second part of the previous post needs to be disregarded
Thanks for the help.