Re: Re: header

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Micah Gersten wrote:
Wouldn't it be nice if in the $_SERVER array you could get the whole URL
now that PHP has a parse_url function?

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com


off on a tangent.. I made this some time ago which is rather useful:

class url {
	
	public $scheme = false;
	public $host = false;
	public $port = false;
	public $user = false;
	public $pass = false;
	public $path = false;
	public $query = false;
	public $fragment = false;
	
	public function __construct( $url = FALSE )
	{
		if( $url !== FALSE ) {
			$this->load( $url );
		}
	}
	
	public function load( $url )
	{
		if( is_string( $url ) && strlen( trim( $url ) ) ) {
			if( ($tempSelf = parse_url( $url )) !== FALSE ) {
				foreach( $tempSelf as $component => $value ) {
					$this->$component = $value;
				}
				return TRUE;
			}
		}
		return FALSE;
	}
	
	public function __toString()
	{
		if($this->scheme) {
			$_string .= $this->scheme . '://';
		}
		if($this->user && $this->pass) {
			$_string .= $this->user . ':' . $this->pass . '@';
		}
		if($this->host) {
			$_string .= $this->host;
		}
		if($this->port) {
			$_string .= ':' . $this->port;
		}
		if($this->path) {
			$_string .= $this->path;
		}
		if($this->query) {
			$_string .= '?' . $this->query;
		}
		if($this->fragment) {
			$_string .= $this->fragment;
		}
		return $_string;
    }
	
}

$url = new url('http://php.net/some.page');

echo $url;
echo $url->scheme;

etc.

Agreed though; it would be nice if PHP had gave access to all the properties in a simple UNIFIED way regardless of the http server software and protocol used.

$_SERVER['HTTP_REQUEST_SCHEME'] = 'http://';
$_SERVER['HTTP_REQUEST_HOST'] = 'php.net';
etc..

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux