39 protected $scheme = null;
46 protected $user = null;
53 protected $pass = null;
60 protected $host = null;
67 protected $port = null;
74 protected $path = null;
81 protected $query = null;
88 protected $fragment = null;
95 protected $regex = array();
106 $uri = explode(
":", strval($uri), 2);
108 $this->scheme = strtolower($uri[0]);
109 $uriString = isset($uri[1]) ? $uri[1] :
"";
111 if(!ctype_alnum($this->scheme))
117 $this->regex[
"alphanum"] =
"[^\W_]";
118 $this->regex[
"escaped"] =
"(?:%[\da-fA-F]{2})";
119 $this->regex[
"mark"] =
"[-_.!~*'()\[\]]";
120 $this->regex[
"reserved"] =
"[;\/?:@&=+$,]";
121 $this->regex[
"unreserved"] =
"(?:" . $this->regex[
"alphanum"] .
"|" . $this->regex[
"mark"] .
")";
122 $this->regex[
"segment"] =
"(?:(?:" . $this->regex[
"unreserved"] .
"|" . $this->regex[
"escaped"] .
"|[:@&=+$,;])*)";
123 $this->regex[
"path"] =
"(?:\/" . $this->regex[
"segment"] .
"?)+";
124 $this->regex[
"uric"] =
"(?:" . $this->regex[
"reserved"] .
"|" . $this->regex[
"unreserved"] .
"|" . $this->regex[
"escaped"] .
")";
126 if(strlen($uriString) > 0)
145 $status = @preg_match(
"~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~", $uriString, $matches);
147 if($status === FALSE)
154 $this->path = (isset($matches[4])) ? $matches[4] :
'';
155 $this->query = (isset($matches[6])) ? $matches[6] :
'';
156 $this->fragment = (isset($matches[8])) ? $matches[8] :
'';
158 $status = @preg_match(
"~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~", (isset($matches[3])) ? $matches[3] :
"", $matches);
160 if($status === FALSE)
167 $this->user = isset($matches[2]) ? $matches[2] :
"";
168 $this->pass = isset($matches[4]) ? $matches[4] :
"";
169 $this->host = isset($matches[5]) ? $matches[5] :
"";
170 $this->port = isset($matches[7]) ? $matches[7] :
"";
193 $uri =
new self(strval($uri));
200 return $uri->valid();
210 return strlen($this->scheme) ? TRUE : FALSE;
233 if($username === null)
235 $username = $this->user;
238 if(strlen($username) == 0)
243 $pattern =
"/^(" . $this->regex[
"alphanum"] .
"|" . $this->regex[
"mark"] .
"|" . $this->regex[
"escaped"] .
"|[;:&=+$,])+$/";
244 $status = @preg_match($pattern, $username);
246 if($status === FALSE)
251 return ($status == 1);
261 return strlen($this->user) ? TRUE : FALSE;
284 if($password === null) {
285 $password = $this->pass;
288 if(strlen($password) == 0)
293 $pattern =
"/^(" . $this->regex[
"alphanum"] .
"|" . $this->regex[
"mark"] .
"|" . $this->regex[
"escaped"] .
"|[;:&=+$,])+$/";
294 $status = @preg_match($pattern, $password);
296 if($status === FALSE)
301 return ($status == 1);
311 return strlen($this->pass) ? TRUE : FALSE;
348 return strlen($this->host) ? TRUE : FALSE;
385 return strlen($this->port) ? TRUE : FALSE;
396 return ($this->
hasPort()) ? intval($this->port) : $default;
413 if(strlen($path) == 0)
418 $pattern =
"/^" . $this->regex[
"path"] .
"$/";
419 $status = @preg_match($pattern, $path);
421 if($status === FALSE)
426 return ($status == 1);
436 return strlen($this->path) ? TRUE : FALSE;
461 $query = $this->query;
464 if(strlen($query) == 0)
469 $pattern =
"/^" . $this->regex[
"uric"] .
"*$/";
470 $status = @preg_match($pattern, $query);
472 if($status === FALSE)
477 return ($status == 1);
487 return strlen($this->query) ? TRUE : FALSE;
503 parse_str($this->query, $queryArray);
515 if(!$this->
hasQuery())
return FALSE;
517 parse_str($this->query, $queryArray);
519 return array_key_exists($key, $queryArray) ? TRUE : FALSE;
531 if(!$this->
hasQuery())
return $default;
533 parse_str($this->query, $queryArray);
535 if(array_key_exists($key, $queryArray))
537 $val = $queryArray[$key];
539 if(ctype_digit($val))
543 elseif(is_string($val))
565 if($fragment === null)
567 $fragment = $this->fragment;
570 if(strlen($fragment) == 0)
575 $pattern =
"/^" . $this->regex[
"uric"] .
"*$/";
576 $status = @preg_match($pattern, $fragment);
578 if($status === FALSE)
583 return ($status == 1);
593 return strlen($this->fragment) ? TRUE : FALSE;
616 return (array_key_exists($key, $_REQUEST) && !empty($_REQUEST[$key])) ? self::stripslashesRecursive($_REQUEST[$key]) : $default;
628 return (array_key_exists($key, $_SERVER) && !empty($_SERVER[$key])) ? $_SERVER[$key] : $default;
640 return (array_key_exists($key, $_SESSION) && !empty($_SESSION[$key])) ? $_SESSION[$key] : $default;
652 if(!preg_match(
"/^([a-z0-9][a-z0-9-]{0,62}\.)*([a-z0-9][a-z0-9-]{0,62}\.)+([a-z]{2,6})$/i", $hostname, $matches))
657 $parts[
"tld"] = $matches[3];
658 $parts[
"2nd"] = $matches[2];
659 $parts[
"3rd"] = $matches[1];
671 $sheme = (self::getHostParam(
"HTTPS") ==
"on") ?
"https" :
"http";
674 $serverPort = self::getHostParam(
"SERVER_PORT");
675 $serverPort = ($serverPort != 80 && $serverPort != 443) ?
":" . $serverPort :
"";
677 if($serverName->endsWith($serverPort))
679 $serverName = $serverName->replace($serverPort,
"");
694 return self::getHostUri()->append(($scriptPath == DIRECTORY_SEPARATOR ?
"" : $scriptPath) .
"/");
707 return stripslashes(strval($var));
710 foreach($var as $key => $val)