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

XF 2.0 External logout

LPH

Well-known member
#1
External login, link to the profile, etc seems to be working but the external logout link returns a message stating:

Security error occurred. Please press back, refresh the page, and try again.
Code:
<?php echo '<a class="xenword_logout logout" href="' . \XF::app()->router()->buildLink( 'canonical:account' ) . '">Profile</a>'; ?>
<?php echo '<a class="xenword_logout logout" href="' . \XF::app()->router()->buildLink( 'canonical:logout', $visitor, array(
      '_xfToken' => $visitor['csrf_token_page'],
      'redirect' => $redirect_out
   ) ) . '">Logout</a>'; ?>
I'm thinking it is the $visitor array but maybe there is a better way to do this rather than the above code.

Update: htmlspecialchars($this->app['csrf.token']) is the value for _xfToken but I'm not calling it right.

Code:
<?php echo '<a class="xenword_logout logout" href="' . \XF::app()->router()->buildLink( 'canonical:logout', $visitor, array(
      '_xfToken' => htmlspecialchars(\XF::app()->app['csrf.token']),
      'redirect' => $redirect_out
   ) ) . '">Logout</a>'; ?>
It's getting a container key app error.

'_xfToken' => htmlspecialchars(\XF::app()->container( 'csrf.token' ) ),
But stuck on the same error.

Thank you for your help.
 
Last edited:

LPH

Well-known member
#2
Almost. This will log out the user but not redirect properly.

Code:
<?php echo '<a class="xenword_logout logout" href="' . \XF::app()->router()->buildLink( 'canonical:logout', $visitor, array(
      't' => htmlspecialchars(\XF::app()->container( 'csrf.token' ) ),
      'redirect' => $redirect_out
   ) ) . '">Logout</a>'; ?>