Re: Re: header

From: Date: Wed, 17 Sep 2008 09:31:50 +0000
Subject: Re: Re: header
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.general 
Request: Send a blank email to php-general+get-280349@lists.php.net to get a copy of this message
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..

« previous php.general (#280349) next »