Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix absolute URL bugs

git-svn-id: http://svn.php.net/repository/pear/packages/Net_URL/trunk@122634 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit b91caf46deba71934b874bbdbe3cddc40f370553 1 parent abba3df
Richard Heyes authored
Showing with 30 additions and 19 deletions.
  1. +30 −19 URL.php
49 URL.php
View
@@ -111,33 +111,44 @@ function Net_URL($url = null, $useBrackets = true)
{
global $HTTP_SERVER_VARS;
- /**
- * Figure out host/port
- */
- if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
- $host = $matches[1];
- if (!empty($matches[3])) {
- $port = $matches[3];
- } else {
- $port = '80';
- }
- }
-
$this->useBrackets = $useBrackets;
$this->url = $url;
- $this->protocol = 'http' . (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 's' : '');
$this->user = '';
$this->pass = '';
- $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
- $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : 80);
- $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
- $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
- $this->anchor = '';
+ $this->host = '';
+ $this->port = 80;
+ $this->path = '';
+ $this->querystring = array();
+ $this->anchor = '';
+
+ // Only use defaults if not an absolute URL given
+ if (!preg_match('/^(https?|ftp|telnet|gopher|file):\/\//', $url)) {
+ /**
+ * Figure out host/port
+ */
+ if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
+ $host = $matches[1];
+ if (!empty($matches[3])) {
+ $port = $matches[3];
+ } else {
+ $port = '80';
+ }
+ }
+
+ $this->protocol = 'http' . (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 's' : '');
+ $this->user = '';
+ $this->pass = '';
+ $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
+ $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : 80);
+ $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
+ $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
+ $this->anchor = '';
+ }
// Parse the url and store the various parts
if (!empty($url)) {
$urlinfo = parse_url($url);
-
+
// Default querystring
$this->querystring = array();
Please sign in to comment.
Something went wrong with that request. Please try again.