In one of my page image.php?id=somenumber , I am using <?php echo $_SERVER['PHP_SELF']; ?> to recognize this page in the common sidebar. But using this $_SERVER['PHP_SELF'] yields also the value of id as image.php?id=32 which I don't want.
How do I only get the filename?
$_SERVER['SCRIPT_NAME'], if you are using Apache at least, should cover what you need. It should be the executed script without the query string and relative to the document root (as opposed to SCRIPT_FILENAME, REQUEST_URI, or PHP_SELF.
$parts = explode('/', $_SERVER["SCRIPT_NAME"]);
$file = $parts[count($parts) - 1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With