2

I need help with this;

I added this line of PHP code in a menu option using sourcerer.

<li style="list-style:none;">
    <?php
    $user = JFactory::getUser(); {
        $userToken = JSession::getFormToken();
        echo '<a href="index.php?option=com_users&view=login&layout=logout' . $userToken . '=1;" >Logout ' .'</a>';
    }
    ?>
</li> 

Now, I need to redirect to a page once the user clicks this menu link.

I would like to redirect the user to the home page.

Now, when I use this link to logout it just goes to an empty page.

What am I doing wrong and how can I fix it?

2

You can do this without Sourcerer. A direct logout link is core behaviour of Joomla.

  • Create a menu item of the type users > logout.
  • Set the redirect option to point to your homepage, or wherever you want it to go.
  • If you need to create a logout link which isn't part of a menu, then just use the link <a href="<?php echo JRoute::_("index.php?Itemid=111"); ?>">LOGOUT</a> replacing 111 with the id of your logout menu item.
  • In a WYSIWYG area, you should be able to just use <a href="index.php?Itemid=111">LOGOUT</a>, as links here should be automatically passed through JRoute without the need for PHP extensions.

I'd strongly advise never to use Sourcerer. It's a hack tool which encourages terrible development practise. Joomla has a strong framework using components and modules which helps keep content, database and styles separate and easy-to-maintain, and which other developers can easily follow. Sourcerer makes maintenance of a site almost impossible. It's bad enough mixing styles and content in a single database cell, let alone styles, server-side code and content.

  • Thanks a lot man I will be giving it a try. I will also look into the advice you gave. Will create the menu link and add the numbers on the end of the URL. Thanks again!\ – MailBlade Mar 25 '17 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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