Is there a way to get the URL of a script in PHP? For example, a PHP page is loaded at www.example.com/example.php . Is there a way to get that URL in the PHP script?
Getting the URL in PHP
Yes
...
....
That does answer your question :rolleyes:
...
...
Oh, go on then.
Do a [man]print_r()[/man] on $_SERVER which is a super-global containing server related data. You'll see a couple of ones which may help you namely SERVER_NAME which is the domain name the script is running on, SERVER_PROTOCOL which is the protocol the script is being served up with (most likely will be HTTP) and then you have a number of variables to get different aspects of the script name. REQUEST_URI is everything after the domain name (local path, script name and query string), or script name is just the script name. With this info you can rebuild exactly what would be appearing in the address bar of the browser. There may be single variable somewhere which holds this already re-built but I doubt it as it's not something which appears all together in the HTTP request.
HTH
Bubble