如何在URL中获取当前页面名称,包括$ _GET变量?

Let's say I have the page:

index.php?page=page-title-here

I want to get the current page name including the $_GET variable in the URL. I am currently using this:

basename(__FILE__)

It outputs "index.php", the actual file name. Any idea how to also include the $_GET variable so that it will output "index.php?page=page-title-here"?

The variable $_SERVER["REQUEST_URI"] gives you the file with GET parameters. Also includes folders in the url.

Edit: Use $page = end(explode('/', $_SERVER["REQUEST_URI"])); if you want to get rid of the folders from the url.

Try...

$page = (__FILE__) . '?' . $_GET['page'];

You can do so using the REQUEST_URI:

echo $_SERVER['REQUEST_URI'];

From the manual:

REQUEST_URI: The URI which was given in order to access this page; for instance

Try $_SERVER['REQUEST_URI'] (there are lots of interesting things in $_SERVER)

You should definitely take a look into a flexible routing mechanism for your application. I suggest:

I also suggest that you read a little bit about the MVC pattern and Front Controller:

To your application, I suggest that You have take a look into a flexible routing mechanism.