current url function

From: Date: Mon, 15 Mar 2004 23:49:12 +0000
Subject: current url function
Groups: php.general 
Request: Send a blank email to php-general+get-180505@lists.php.net to get a copy of this message
hey! i am working in an open source development, and have done a function that gives me the current url, but i need it to work always, everywhere, in every server with all browsers, could you tell me if you think it will or if you have any suggestions? here is the code: /* Returns the current URL TODO: The function can not manage nor return user and pass in the URL if present because it seems that you can not fetch them from PHP (or at least I dont't know how to do it :P) LIMITATIONS: fragment (after # sign) can not be fetched since it is a client-side feature */ function url($host=true, $querystring=true) { $url = ''; if($host) { if ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') || (!empty($_ENV['HTTPS']) && $_ENV['HTTPS']=='on') ) $url = 'https://'; else $url = 'http://'; $url .= !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; //if((int)$_SERVER['SERVER_PORT']!=80) $url .= ':' . $_SERVER['SERVER_PORT']; } //$url .= $_SERVER['SCRIPT_NAME']; //if($querystring && !empty($_SERVER['QUERY_STRING'])) $url .= '?' . $_SERVER['QUERY_STRING']; if($querystring) $url .= $_SERVER['REQUEST_URI']; else $url .= $_SERVER['PHP_SELF']; return $url; } thanx in advance! luis.

« previous php.general (#180505) next »