Actions

Difference between revisions of "JURI/isInternal"

From Joomla! Documentation

(New page: A static method that returns '''true''' if the URI supplied is "internal" to the current Joomla installation; otherwise it returns '''false'''. ===Syntax=== boolean isInternal( $uri ) whe...)
 
m (See also: re-categorisation)
 
Line 56: Line 56:
 
===See also===
 
===See also===
 
* [http://api.joomla.org/Joomla-Framework/Environment/JURI.html#isInternal JURI->isInternal on api.joomla.org]
 
* [http://api.joomla.org/Joomla-Framework/Environment/JURI.html#isInternal JURI->isInternal on api.joomla.org]
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JURI]]</noinclude>
+
<noinclude>[[Category:JURI]]</noinclude>

Latest revision as of 11:35, 9 August 2012

A static method that returns true if the URI supplied is "internal" to the current Joomla installation; otherwise it returns false.

Syntax

boolean isInternal( $uri )

where:

Argument Data type Description Default
$uri string URI to be tested against the Joomla installation URI.

Example

In this example, the Joomla site URI is shown and a number of sample URIs tested against it.

echo 'Joomla URI is ' . JURI::base() . "\n";
$array = array( 'http://localhost/joomla/index.php',
                'http://localhost/anotherjoomla/index.php',
                'http://localhost/joomla:8080/index.php',
                'http://localhost/joomla:80/index.php',
                'http://127.0.0.1/joomla/index.php',
                'http://localhost/joomla/administrator/index.php',
                'http://localhost/joomla/administrator/index.php?task=view&id=32#anchorthis',
                'https://localhost/joomla/index.php'
              );
foreach ($array as $key => $uri) {
    echo ($key+1) . ': ' . $uri . ' is ';
    echo JURI::isInternal( $uri ) ? 'internal' : 'external';
    echo "\n";
}

would output

Joomla URI is http://localhost/joomla/
1: http://localhost/joomla/index.php is internal
2: http://localhost/anotherjoomla/index.php is external
3: http://localhost/joomla:8080/index.php is external
4: http://localhost/joomla:80/index.php is external
5: http://127.0.0.1/joomla/index.php is external
6: http://localhost/joomla/administrator/index.php is internal
7: http://localhost/joomla/administrator/index.php?task=view&id=32#anchorthis is internal
8: https://localhost/joomla/index.php is external

Noting that:

  1. Is internal because the base URIs are identical.
  2. Is external because the path to the Joomla installation is different.
  3. Is external because the port numbers differ.
  4. Is external because the port numbers differ, even though port 80 is the default port for the HTTP protocol.
  5. Is external because the host names differ, even though 127.0.0.1 resolves to 'localhost'.
  6. Is internal even though the paths differ.
  7. Is internal even though the paths, queries and fragments differ.
  8. Is external because the schemes differ.

See also