Skip to content

Instantly share code, notes, and snippets.

@esedic
Created September 25, 2025 09:05
Show Gist options
  • Save esedic/badcc04faeaa2e8ca5d2eeb33f9f3b50 to your computer and use it in GitHub Desktop.
Save esedic/badcc04faeaa2e8ca5d2eeb33f9f3b50 to your computer and use it in GitHub Desktop.
Get Current URL in Joomla 3 with PHP
<?php
// Method 1: Using JUri (Recommended)
// Get the full current URL
$currentUrl = JUri::getInstance()->toString();
// Get only the base URL (without query parameters)
$baseUrl = JUri::base();
// Get the current URI path
$uri = JUri::getInstance();
$path = $uri->toString(array('path', 'query', 'fragment'));
// Example usage in a Joomla component or module
echo "Full URL: " . $currentUrl;
echo "Base URL: " . $baseUrl;
// Method 2: Using JApplication (Alternative)
$app = JFactory::getApplication();
$uri = JUri::getInstance();
// Get full URL
$currentUrl = $uri->toString();
// Or get it from the application
$currentUrl = $app->get('uri')->toString();
// Method 3: Getting Specific Parts of the URL
$uri = JUri::getInstance();
// Get different parts of the URL
$scheme = $uri->getScheme(); // http or https
$host = $uri->getHost(); // domain.com
$path = $uri->getPath(); // /path/to/page
$query = $uri->getQuery(); // query parameters
$fragment = $uri->getFragment(); // anchor part
// Build custom URL
$customUrl = $scheme . '://' . $host . $path;
// Method 5: Getting Query Parameters
$input = JFactory::getApplication()->input;
$currentUrl = JUri::getInstance()->toString();
// Get specific query parameters
$id = $input->getInt('id');
$view = $input->getCmd('view');
// Add or modify query parameters
$uri = JUri::getInstance();
$uri->setVar('new_param', 'value');
$modifiedUrl = $uri->toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment