tags:

views:

193

answers:

4

How do I return the entire url of a page including get.

$_SERVER['HTTP_REFERER'] and php_self doesn't do it.

they return www.domain.com/example instead of www.domain.com/example?user=2

+3  A: 

Try:

echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

If you don't wish to return the domain, but just the internal url and get variables you can omit $_SERVER['HTTP_HOST'].

BrynJ
ahh thanks, exactly what i wanted.
payling
A: 

$_SERVER['REQUEST_URI'] contains the requested URL path and query.

Gumbo
A: 

$_SERVER['REQUEST_URI'] is probably what you are looking for, just remember that you will need to encode it if you wish to send that in a "GET".

Chris S
+1  A: 

One other thing, $_SERVER is an array, so are $_GET, $_POST, $_SESSION and $_COOKIE

So if you're not sure if the data is contained within those variables, then try something like this.

echo "<pre>";
print_r($_SERVER);
echo "</pre>";
Ólafur Waage