hey guys, i know it's not the best way of doing this but the whole thing is just a little project which doesn't need anything more difficult.
i'm passing directory names along with my url like domain.com?p=folder/subfolder/etc
i'm looking for the best way to check if the dir exists and i want to (at least) kind of prevent people from going up in hierarchy.
now what i'm doing right now (almost) works, however i think there's a much better and easier and shorter way for that:
if(isset($_GET['p'])) {
if (realpath($_GET['p'])) {
if (substr(PATH, 0, 1) == "" || substr(PATH, 0, 1) == "/" || substr(PATH, 0, 2) == "./" || substr(PATH, 0, 3) == "../") {
print "directory is forbidden!";
} else {
define(PATH, $_GET['p']);
}
} else {
print "directory does not exist!";
}
} else { define(PATH, "root"); }
what would you do?