PHP Get URL

To get the current url of the page in PHP you need to access the $_SERVER globals. This is a quick and easy way to get the current url (whether http or https) to use it inside your application.

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

About this entry