Icon

Irimis'S Blog

NOT just another blog.

Joomla! and SID in URI

On last project I’ve worked, I needed to pass the SID trough URI on entire website. The website was builded on Joomla! platform.

Joomla! is not offering natively anything for such thing and i had to find quickly a solution to fix this.

First solution, was to add these lines

$session =& JFactory::getSession();

$uri->setVar($session->getName(), $session->getId());

in includes/router.php, function build, before

return $uri;

Second solution, was fixing this with a plugin

	// no direct access
	defined( '_JEXEC' ) or die( 'Restricted access' );

	jimport( 'joomla.plugin.plugin' );

	class plgSystemSid extends JPlugin {

		function onAfterInitialise() {

			// Get application
			$application =& JFactory::getApplication();

			// Get router
			$router =& $application->getRouter();

			// Add the SID rule
			$router->attachBuildRule(array(&$this, 'addSidToUri'));
		}

		function addSidToUri(&$router, &$uri) {

			// Add SID to query
			$session =& JFactory::getSession();
			$uri->setVar($session->getName(), $session->getId());
		}

	}

Download Joomla! SID to URI (142) plugin.