getting the url for the current page

Status
Not open for further replies.

SyncViews

New Member
Messages
37
Reaction score
0
Points
0
How can I get the url for the current page in php?

I tried these but none returned the exact url :(


$_SERVER['SCRIPT_NAME']
$_SERVER['PHP_SELF']
__FILE__

I just want it to to just get the same url as dsiplayed in the user adress bar.. (includeing the domain and ?myvar = value etc)
 

kajasweb

New Member
Messages
1,723
Reaction score
0
Points
0
Use the following snippet...
PHP:
$URL = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if(substr($URL,strlen($URL) - 1) != "/") { $URL .= "/"; }
$URL .= $_SERVER['PHP_SELF'];
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
PHP:
$URL = $_ENV['HTTP_HOST].$_ENV['REQUEST_URI'];

Ought to do it.
 
Last edited:
Status
Not open for further replies.
Top