Skip to content
Greg Bowler edited this page Jul 3, 2018 · 19 revisions

A URI (Universal Resource Identifier) is a sequence of characters that identify the World Wide Web request being made. Sometimes referred to as a URL (Universal Resource Locator) or URN (Universal Resource Name), with extremely subtle differences, we shall use the term URI for consistency with PHP's internal naming conventions.

A simple URI https://www.example.com/colour/red is made up of the following parts:

  • https - the URI scheme / protocol being used to make the request
  • www.example.com - the host (otherwise referred to as the hostname)
  • /colour/red - the path

A complex URI https://henry:[email protected]:8301/colour/red?sort=price&filter=new#options is made up of the following parts:

  • https - the URI scheme / protocol being used to make the request
  • henry:s3cr3t - the user info
  • www.example.com - the host (otherwise referred to as the hostname)
  • 8301 - the port
  • /colour/red - the path
  • sort=price&filter=new - the query or querystring
  • option - the fragment

Throughout PHP.Gt, wherever a URI is referenced, an object that implements PSR-7's UriInterface is used.

Accessing the current URI in a WebEngine application

In WebEngine applications, all superglobals are protected, which means the $_SERVER superglobal is not available. Instead, the values of $_SERVER are exposed through the Server class (part of PHP.Gt/Http) and encapsulated within your Page Logic.

From within any Page Logic class, you can obtain the current requested URI using the getRequestUri function of the Server object, as follows:

public function checkCurrentURI() {
	$uri = $this->server->getRequestUri();
	$host = $uri->getHost();
	$path = $uri->getPath();

	$this->doSomethingWithUriParts($host, $path);
}
Clone this wiki locally