Alex Rivera | Logout

How do I get the current URL of my script using PHP?

Asked 2009-12-09T05:28:25.350
15

How do I get the current URL of my script using PHP?

Edit
Report

1 Answer

32

Please see PHP Get Current URL:

Sometimes it is not as straightforward as one may think to get the current url to use it inside your application. Here is a snippet that I use to fetch the current URL and use it in a script. The current url (whether http or https) is now a local variable that you can do with as you please.

$url = "http".(!empty($_SERVER['HTTPS'])?"s":"").
"://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

Note: You should groom this value before using in anything sensitive, like a sql query.

answered 2009-12-09T05:30:23.183

Your Answer