Reputation: 4716
I am trying to get the entire page URL as a string in PHP - so, if the requested URL is ./foo.php?arg1=test&arg2=test2
, I get "./foo.php?arg1=test&arg2=test2"
.
I know that I can get the ./foo.php
part from $_SERVER
and the variables from $_GET
, but I was wondering if there's an easy way to do it in just one fell swoop.
TIA.
Upvotes: 2
Views: 2460
Reputation: 28721
$url = (isset($_SERVER['HTTPS']) == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
This should return the full url based on what was typed in the address bar.
Upvotes: 6
Reputation: 5674
$_SERVER['REQUEST_URI']
https://www.php.net/manual/en/reserved.variables.server.php
Upvotes: 0
Reputation: 401152
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']
might be what you are looking for...
Upvotes: 4