Hello, I want to save the url of a page in a variable so that I can use it later. There are many pages I want to do that to so writing it manually everytime like this: $variable="http://www.foo.com/foo1.html"; isn't an option. There has to be a php function that can get the url from the browser, right? I'd appreciate some help.
$uri = 'http' . (!empty($_SERVER['HTTPS']) ? 's' : null) . '://' . $_SERVER['HTTP_HOST'] . ($_SERVER['SERVER_PORT'] != 80 ? ":{$_SERVER['SERVER_PORT']}" : null) . $_SERVER['REQUEST_URI']; echo $uri; PHP:
Note that the code above takes care of https connections and other ports than the default. In most cases something like this is enough: $uri = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; PHP: