Search code examples
joomla3.0

JFactory::getApplication()->redirect() convert & to &


I have a problem in Joomla 3.6.2 when using JFactory::getApplication()->redirect() with route to index.php?option=com_users&view=login AND the return parameter.

The code looks like this.

$uri = urlencode(base64_encode(JURI::getInstance()->toString()));
JFactory::getApplication()->redirect(
    JRoute::_('index.php?option=com_users&view=login&return='. $uri),
    JText::_("YOU_MUST_BE_LOGGED_IN_TO_ACCESS_THIS_CONTENT", 'com_portail')
);

Where $uri would be something like this:

aHR0cDovL2xvY2FsaG9zdC9wb3J0YWlsL2luZGV4LnBocD9vcHRpb249Y29tX3BvcnRhaWw=

With this method I get redirected to something like that:

http://localhost/portail/index.php/component/users/?view=login& amp;return=aHR0cDovL2xvY2FsaG9zdC9wb3J0YWlsL2luZGV4LnBocD9vcHRpb249Y29tX3BvcnRhaWw=

In particular

Note the & that causes my page to fail to load.

Any ideas?

Thanks


Solution

  • if you use JRoute set the second parameter to false and it should work.

    So your code should somewhat look like this

    JFactory::getApplication()->redirect(
            JRoute::_('index.php?option=com_users&view=login&return='. $uri, false), 
            JText::_("YOU_MUST_BE_LOGGED_IN_TO_ACCESS_THIS_CONTENT", 'com_portail')
            );
    

    Explanaition should be found in the JRoute-Docs :)

    regards