PDA

View Full Version : Getting the path


codefox
01-15-2003, 06:53 AM
I use the following function to get the URL of the current document. It works fine when the version of PHP is >= 4.1.0 but does not give the HTTP_HOST for versions below, so the link looks like http:///somedoc.php. Any suggestions?
function GetDocumentURL()
{
$ver = str_replace(".", "", phpversion());
if ($ver < 410) {
global $PHP_SELF;
return "http://" . $HTTP_SERVER_VARS['HTTP_HOST'] . $PHP_SELF;
}
else
return "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
}


Thanks.

Spookster
01-16-2003, 04:29 PM
http://codingforums.com/showthread.php?s=&threadid=12816

codefox
01-17-2003, 04:57 AM
Thanks, that helped.

codefox
01-19-2003, 01:29 PM
This works:
<?php
function GetDocumentURL()
{
$ver = str_replace(".", "", phpversion());
if ($ver < 410) {
global $HTTP_SERVER_VARS, $SERVER_NAME;
return "http://" . $SERVER_NAME . $HTTP_SERVER_VARS['PHP_SELF'];
}
else
return "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
}
?>