The JUri Class can be used to get information about the Joomla URI.
This class serves two purposes.
It parses a URI and provides a common interface for the Joomla Platform to access and manipulate a URI.
It obtains the URI of the current executing script from the server regardless of server.
$uri = JUri::getInstance();
It returns the global JUri object, only creating it if it doesn't already exist.
The URL stands for Uniform Resource Locator. The URI stands for Uniform Resource Identifier. A URI can be a name, locator, or both for an online resource whereas a URL is just the locator. URLs are a subset of URIs.
A URL is normally made up of four components:
Scheme: The scheme identifies the protocol used to access the resource on the Internet. It can be HTTP (without SSL) or HTTPS (with SSL).
Host: The host name identifies the host that holds the resource. For example, www.example.com. Host names can also be followed by a port number. Well-known port numbers are normally omitted from the URL.
Path: The path identifies the specific resource in the host that the web client wants to access. For example, /documentation/joomla/index.html.
Query String: The query string follows the path. It provides information that the resource can use for several purpose. For example, as parameters for a search or as data to be processed. The query string is usually a string of name and value pairs. For example, view=article. Name and value pairs are separated from each other by an ampersand (&). For example, view=article&search=joomla.
The scheme is followed by a colon and two forward slashes. If a port number is specified, that number follows the host name, separated by a colon. The path name begins with a single forward slash. If a query string is specified, it is preceded by a question mark.
A URL can be followed by a fragment identifier. The separator used between the URL and the fragment identifier is the # character. A fragment identifier is used to point a web browser to a reference or function in the item that it has just retrieved. For example, if the URL identifies an HTML page, a fragment identifier can be used to indicate a subsection within the page, using the ID of the subsection.
1. To get the global JUri object, only it if it doesn't already exists.
$uri = JUri::getInstance();
2. To get the complete or full URI
3. To get the scheme (http or https)
To check if the scheme uses SSL
4. To get the host
It returns the hostname or ip or null if no hostname or ip was specified.
5. To get the base URL or root URL
6. To get the path of URL after the root.
It includes a forward slash at the starting and excludes any query string parameters.
7. To get the URL without any query string parameters
8. To get the query string parameters
Add the boolean true argument to get query string parameters as array.
$arr = $uri->getQuery(true);
To get a specific query string variable by name
You can also declare a default value as the second argument if the variable is not set.
To check if a variable exists
9. To Remove an item from the query string variables if it exists
10. To get URI port number
It returns null if no port was specified.