1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirect to specified URL on logout?

Discussion in 'XenForo Development Discussions' started by RickM, Feb 26, 2012.

  1. RickM

    RickM Well-Known Member

    Hi all,

    I've managed to implement a bridge between XenForo and PyroCMS, however need to get this one last thing working before being able to release.

    I need to make it so that if on the PyroCMS installation you click logout, it brings you back to the same page after logging out.

    I noticed some redirection options in the XenForo logout controllerpublic file but cant seem to get it to work.

    Has anyone managed to get this working?

    Thanks
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Can you just add something like name="redirect" value="{$requestPaths.requestUri} to the template?
     
  3. RickM

    RickM Well-Known Member

    I'll have to give it a try and see. Was hoping to be able to keep it as a standard link (e.g site.com/forums/logout?redirect=site.com/some-page) instead of via POST.

    I guess I could do an addon for it if its not possible though.
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That works too.
     
  5. RickM

    RickM Well-Known Member

    Doesnt seem to work for me :( - will carry on playing around with it seeing if I can get it to work though.
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    In my testing this only works if you use the "direct" logout link (the one that doesn't ask for confirmation):

    Screen shot 2012-03-01 at 2.50.19 PM.png

    If it asks you for logout confirmation then that form does not accept a redirect.
     
  7. Acid

    Acid Active Member

    Have you solved this yet?
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    An addon is required to add a redirect to the "confirmation" logout link.

    Or you can edit the templates to make that link not ask for confirmation:

    Admin CP -> Appearance -> Templates -> navigation_visitor_tab

    At the bottom of the template, add the blue code, remove the red code:

    Code:
    		</div>
    	</li>
    	
    	<xen:hook name="navigation_visitor_tabs_end" />
    
    	<li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}'}" class="navLink visitorTabItem OverlayTrigger">{xen:phrase log_out}</a></li>
    </ul>
    
    That will also allow you to add the redirect code so the user is taken back to the same page after they logout:

    Code:
    		</div>
    	</li>
    	
    	<xen:hook name="navigation_visitor_tabs_end" />
    
    	<li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}', 'redirect={$requestPaths.requestUri}'}" class="navLink visitorTabItem OverlayTrigger">{xen:phrase log_out}</a></li>
    </ul>
    
     
  9. Acid

    Acid Active Member

    Thanks mate, that worked. The Overlay window doesn't show anymore.
    One more question though. I'm trying to set a redirect to an external link (not a forum path). How do I do that? Redirect=URL?
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    In my testing you cannot specify a full URL for the redirect location.

    One option is to create a small PHP script to handle the redirect to the URL:

    PHP:
    <?php

    header
    ("Location: http://www.apple.com/");

    ?>
    Then make the logout link redirect to that script.
     
    Acid likes this.
  11. ragtek

    ragtek Guest

    you could also change this by overwriting XenForo_ControllerPublic_Logout::actionIndex()
    this would also allow you easier to define dynamic exit pages(e.g advertisement,redirect to portal index page,etc...)
     
  12. Acid

    Acid Active Member

    Thanks, that worked just fine ;)
     
  13. n1cks21

    n1cks21 Member

  14. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    My previous posts pretty much cover it. It shows how you can specify a redirect location in the templates. And a small custom script can be used to redirect to full URLs. Do you have any questions about this?
     
  15. n1cks21

    n1cks21 Member

    yes can you please post a step by step guide as I am a total noobie when it comes to code and editing templates
     
  16. n1cks21

    n1cks21 Member


    Sorry for the long delay, but could you please please please please please please help me understand the redirect process, I know how to implement the above code, buts thats where I get stuck, where do I actually insert the redirect forum path ? I don't want to redirect to a full url so I assume I don't need to use the above PHP script ? I just want to redirect to my portal page http://www.uk-alliance.com/xenforo/portal/
     
    saurabh likes this.
  17. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Replace {$requestPaths.requestUri} with /xenforo/portal/. That should do it.
     
  18. n1cks21

    n1cks21 Member

    Thank you for the info, it's much appreciated

    I have added
    Code:
    <li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}', 'redirect=/xenforo/portal/'}" class="navLink visitorTabItem">{xen:phrase log_out}</a></li>
    to the bottom of the navigation_visitor_tab template

    That has removed the confirmation box and redirects me to my portal if I log off using this "Log Out" link
    Image2.jpg

    however if I use this "Log Out" link the confirmation box is still removed but it doesn't redirect me to my portal? have I missed something ?

    Image 1.jpg

    Thanks again
     

Share This Page