Get full page url from PHP

I'm trying to get the entire url of a page as a string in PHP, so if the requested url ./foo.php?arg1=test&arg2=test2

is what I get "./foo.php?arg1=test&arg2=test2"

.

I know I can get ./foo.php

some of $_SERVER

and variables from $_GET

, but I was wondering if there is an easy way to do this in one fell swoop.

TIA.

+2


source to share


3 answers


If I open the following URL in my browser:

http://tests/temp/temp.php?a=145&b=glop

      

The following piece of code:

var_dump($_SERVER['REQUEST_URI']);

      



Gives me:

string '/temp/temp.php?a=145&b=glop' (length=27)

      

So, $_SERVER['REQUEST_URI']

maybe what you are looking for ...

+4


source


$url = (isset($_SERVER['HTTPS']) == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

      



This should return the full url based on what was entered in the address bar.

+6


source


0


source







All Articles