Search code examples
phperror-handlingjoomla2.5

How to track jos-Error in Joomla 2.5?


I made one of my menu items only for Guests (not logged in users). ANd If user logs in, it disappears from menu. It works fine...

But I noticed that when I put the link to the Guest menu item in browser, when I'm lnot ogged in , it shows very disgusting jos-Error: You are not authorised to view this resource.

I want to find a way to track such errors and redirect to custom 404 page or some other page.

Please, assist me in this issue.

Thanks


Solution

  • The string You are not authorised to view this resource located in JERROR_ALERTNOAUTHOR language string and fire in includes/application.php function:

    public function authorise($itemid)
        {
            $menus  = $this->getMenu();
            $user   = JFactory::getUser();
    
            if (!$menus->authorise($itemid))
            {
                if ($user->get('id') == 0)
                {
                    // Redirect to login
                    $uri        = JFactory::getURI();
                    $return     = (string)$uri;
    
                    $this->setUserState('users.login.form.data', array( 'return' => $return ) );
    
                    $url    = 'index.php?option=com_users&view=login';
                    $url    = JRoute::_($url, false);
    
                    $this->redirect($url, JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'));
                }
                else {
                    JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
                }
            }
        }
    

    You could alter this function and add redirection or change the text string with your desired message.

    Redirect could be done with redirect() method.

    An example of redirect syntax:

    $app = JFactory::getApplication();
    $app->redirect(JRoute::_(JURI::root().'index.php'));
    

    Please make sure that you won't alter application.php without creating an override system plugin.

    Hope this helps