Topic: how to implement a logout link

hi,

My site uses PunBB. I wanted to put a logout link on my website outside the forum. I tried using this:

<a href="/forum/login.php?action=out&id=<?= $forum_user['id']?>&csrf_token=<?= echo generate_form_token(forum_link($forum_url['login'])) ?>">Logout</a>

But it throws me to the login page with the following confirmation:


Please confirm or cancel your last action

Unable to confirm security token. A likely cause for this is that some time passed between when you first entered the page and when you submitted a form or clicked a link. If that is the case and you would like to continue with your action, please click the Confirm button. Otherwise, you should click the Cancel button to return to where you were.

<confirm> <cancel>

How do I generate the csrf_token correctly?

Re: how to implement a logout link

Try this peace of code:

<a href="/forum/login.php?action=out&id=<?= $forum_user['id']?>&csrf_token=<?= generate_form_token('logout'.$forum_user['id']) ?>">Logout</a>

3 (edited by viktop 2009-08-27 00:15)

Re: how to implement a logout link

Slavok wrote:

Try this peace of code:

<a href="/forum/login.php?action=out&id=<?= $forum_user['id']?>&csrf_token=<?= generate_form_token('logout'.$forum_user['id']) ?>">Logout</a>

Thank you, it worked! smile

Re: how to implement a logout link

Thanks - this helped me too.

Is there a way to add a redirect_url to the logout link?

Re: how to implement a logout link

balder wrote:

Is there a way to add a redirect_url to the logout link?

You can add it like url encoded GET-parameter and edit the 165 line of "<FORUM_ROOT>/login.php".