Thursday, July 30, 2009

How to find the URL of current page in PHP?

I am making a simple webpage with some parameters in PHP. My question is, when a user loads the webpage though any parameter passed, what is a simple way to get the url of the page in PHP. Thanks in advance!

How to find the URL of current page in PHP?
You can get the URI by using the following tag:





$_SERVER['REQUEST_URI'];





There for if the address is http://www.mysite.com/path/to/page, this value would return "/path/to/page".





If you have query string parameters, you can also get those in a similar fashion.





$_GET['page'];





For example, if your address is http://www.mysite.com?page=homepage the above would return "homepage"
Reply:Try





$_SERVER["PHP_SELF"]
Reply:If the page is loaded you don't need the url, you are there already. I think you need to explain.


No comments:

Post a Comment