I have a simple div which I don't want to load if the visitor loads up a certain URL.
It looks like this:
<?php
if( stristr($_SERVER['PHP_SELF'], 'blog') == FALSE )
{
echo "<div id="stuff"></div>";
}
?>
Problem is... it doesn't work... when I load up www.url.com/blog the div#stuff still shows.
Am I just lacking sleep or should the above work? What would you do to not have a div display if the url contains blog ?
Try $_SERVER['REQUEST_URI']
instead:
if (substr($_SERVER['REQUEST_URI'], 0, 5) !== '/blog') {
echo '<div id="stuff"></div>';
}
REQUEST_URI
contains the requested URI path and query and not just the filename of the currently executing script like PHP_SELF
does.
OP's version works for me. Provided that you fix the echo() syntax error.
echo "<div id=\"stuff\"></div>";
tested on PHP Version 5.2.9
try using the === operator as per the 2nd example on:
http://us2.php.net/manual/en/function.stristr.php