Topic: Return URL after login/logout

A while ago I found a post on here that helped me insert a login/logout form on the rest of my site.
I now can't find that post and think I need to change something as when I logout the redirect often doesn't return the browser to the correct URL.

Anyone know how to fix that problem?

--Alan

Re: Return URL after login/logout

From login.php:

redirect(htmlspecialchars($_POST['redirect_url']), $lang_login['Login redirect']);

Re: Return URL after login/logout

ok, found that but what do I do with it?

Login works fine, but when I logout I'm automatically returned to the messageboard and not to the page from which I logged out.

Does that make more sense?

--Alan

Re: Return URL after login/logout

else if ($action == 'out')
{
        if ($pun_user['is_guest'] || !isset($_GET['id']) || $_GET['id'] != $pun_user['id'])
        {
                header('Location: index.php');
                exit;
        }

        // Remove user from "users online" list.
        $db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$pun_user['id']) or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());

        // Update last_visit (make sure there's something to update it with)
        if (isset($pun_user['logged']))
                $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data', __FILE__, __LINE__, $db->error());

        pun_setcookie(1, random_pass(8), time() + 31536000);

        redirect('index.php', $lang_login['Logout redirect']);
}

Change where it redirects to?

Re: Return URL after login/logout

Yup, and somebody did post code on here somewhere of how to do that, but I'm damned if I can find it.
This is a fix that I've previously used, doh!

Thanks for your help.

--Alan

Re: Return URL after login/logout

I found the solution in this thread (thanks ontap).

In login.php
Line 102

replace
    redirect('index.php', $lang_login['Logout redirect']);

with
    redirect($_SERVER['HTTP_REFERER'], $lang_login['Logout redirect']);

Simple!

I think this would be an ideal feature request/change as it makes sense that you're always returned to the page you logged out from.
Agree?

--Alan

Re: Return URL after login/logout

You should use the following code instead, in case the user hasn't sent an HTTP referrer.

if($_SERVER['HTTP_REFERER'] != '')
    redirect($_SERVER['HTTP_REFERER'], $lang_login['Logout redirect']);
else
    redirect('index.php', $lang_login['Logout redirect']);
Looking for a certain modification for your forum? Please take a look here before posting.

Re: Return URL after login/logout

Thanks!

Should I bother mentioning it as a feature request?

--Alan

Re: Return URL after login/logout

If it's something you really think is important, then go ahead, but I think it will end up read here anyway. smile

Looking for a certain modification for your forum? Please take a look here before posting.

10 (edited by Surkow 2007-10-11 19:08)

Re: Return URL after login/logout

I almost finished the integration of punbb into my website and found this page after using the search option. Currently when you login on the forum you get redirected the the page you came from. When I login from the frontpage this does not happen. After looking at the code I came to the conclusion I could only use a static page to go to when you login from the frontpage. What code should I add to the pages that are not a part of the forum when you login via login.php to get back to those pages after logging in?