6

I want redirect users after login Current link in joomla 2.5 custom component I use this code but after login i have error 500

          $user =& JFactory::getUser();
          $mainframe  = JFactory::getApplication();
            if($user->id == 0){
                $uri =& JFactory::getURI();
                $url = base64_encode($uri->toString());
                $returnurl = JRoute::_('index.php?option=com_users&view=login&return='.base64_encode($url));        
                $mainframe->Redirect($returnurl,JText::_('Please Login'));
            } 

how can do it?

1 Answer 1

4

Try:

$url = base64_encode(JUri::current());
$returnurl = JRoute::_('index.php?option=com_users&view=login&return='.$url, false); //false will make the URL non-xhtml
$mainframe->redirect($returnurl,JText::_('Please Login'));
7
  • thank I using your code but I have error 500 yet. when click login go to this link: index.php/component/users/?task=user.login and have error 500
    – saber
    Dec 17, 2014 at 7:00
  • Try turning off SEF and see if it works. Do you have a 3rd party SEF extension installed?
    – Mike Feng
    Dec 17, 2014 at 8:07
  • when off SEF it's work but redirect to home page after login and do not use SEF extension only use default joomla
    – saber
    Dec 17, 2014 at 8:22
  • I enable SEF and Adds Suffix to URL now it's work but i want redirect after login to submitted menu but now redirect to user profile
    – saber
    Dec 17, 2014 at 8:28
  • You would need to do some debugging then. There's nothing wrong with the above code. Try outputting JUri::current(), $url, and $returnurl variables to make sure they're correct.
    – Mike Feng
    Dec 17, 2014 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.