Reputation: 987
I need a certain image to display on my website in second-level subdirectories only. So if my URL is www.mywebsite.com/
or www.mywebsite.com/subdirectory1/
then I don't want the image to appear.
However if my URL is www.mywebsite.com/subdirectory1/subdirectory2/
then I do want the image to appear.
How would I go about determining if I'm in a second-level subdirectory using PHP? Would I use is_dir
?
Upvotes: 0
Views: 339
Reputation: 16709
you could do:
$path = parse_url($url, PHP_URL_PATH);
if($path){
$elements = explode('/', trim($path, '/'));
if(count($elements) > 1){
// show the image...
}
}
(PS: the URL needs to start with a scheme, like http://
, or //
)
Upvotes: 1
Reputation: 3288
if (count(explode("/",$_SERVER["SERVER_NAME"]))>=3) {
echo "IM IN 2nd LEVEL";
} else {
echo "IM ONLY A 1st LEVEL";
}
Should do it its abit of a hack but works.
Upvotes: 1