Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to view only file name by $_SERVER['PHP_SELF'] and not GET values appended with it

Tags:

php

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?

like image 455
Tom Avatar asked Dec 21 '25 04:12

Tom


2 Answers

$_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.

like image 190
Explosion Pills Avatar answered Dec 22 '25 19:12

Explosion Pills


$parts = explode('/', $_SERVER["SCRIPT_NAME"]);
$file = $parts[count($parts) - 1];
like image 37
Shoe Avatar answered Dec 22 '25 18:12

Shoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!