MyBB Community Forums

Full Version: Redirect Issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

We have had an issue on our forum pointed out to us.

If a user visits the forum and is not signed in (i.e. is viewing as a guest) then they decide to login there is an issue with the redirect.

When they login, they see the redirect message "You will now be taken back to where you came from" but they are not. They are redirected to the index page.
This is quite annoying for the members, they could be reading a post, decide to reply but first need to login. But when they do, they lose the post they were about to reply to and end up on the index page.

The forum is www . kettle bell forum . co . uk (just remove spaces)
I have created a test user for anyone who is willing to look at this for me.

User: testaccount
Password: testing

MyBB version is 1.6.6

Many thanks for any advice you can give.
*bump*

Does anyone have any advice on this issue please?

Many thanks
The problem is actually in your theme. Open "header_welcomeblock_guest" template and find;
<input type="hidden" name="action" value="do_login" />
and Add the following code just BELOW it;
<input type="hidden" name="url" value="{$redirect_url}" />

Next open ./inc/functions.php and find if the following code is present in your file?
if($_SERVER['HTTP_REFERER'])
{
	$redirect_url = htmlentities($_SERVER['HTTP_REFERER']);
}
else
{
	$redirect_url = '';
}
Hi and thanks for the reply

I added the code into header_welcomeblock_guest.

I also checked inc/functions.php and the code you have quoted is indeed included in the file.

I tested after adding the code into header_welcomeblock_guest but the issue is still present.

Do you have any further advice please?

Thanks, really appreciate the help.
I have attached functions.php in case the issue is with this file.

Many thanks
Ok this is driving me a bit crazy!

It HAS to be something in the template as we have a second template which is loaded on mobiles and the redirect function to the last URL when logging in is working fine, so functions.php must be OK.

Here is the login form from header_welcomeblock_guest can anyone spot anything obvious as to why when logging in you are taken to the index page as opposed to the page you logged in from?

<form action="member.php" method="post">
<input type="hidden" name="action" value="do_login" />
<input type="hidden" name="url" value="{$redirect_url}" />
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong><span class="smalltext">{$lang->login_username}:</span></strong>&nbsp;&nbsp;</td>
<td><input type="text" class="textbox" name="username" title="{$lang->login_username}" value="{$lang->login_username}" onfocus="this.value=''" />
</td>
</tr>
<tr>
<td><strong><span class="smalltext">{$lang->login_password}:</span></strong>&nbsp;&nbsp;</td>
<td><input type="password" class="textbox" name="password" title="{$lang->login_password}" value="{$lang->login_password}" onfocus="this.value=''" /></td>
</tr>

<tr>
<td><strong><span class="smalltext">{$lang->remember_me}:</span></strong>&nbsp;&nbsp;</td>
<td><input type="checkbox" class="checkbox" name="remember" checked="checked" value="yes" />&nbsp;&nbsp;<input type="submit" class="button" name="submit" value="{$lang->welcome_login}" />
</td>
</tr>


<tr>
<td height="30px" colspan="2" valign="middle">
                <strong><span class="smalltext">
                <a href="{$mybb->settings['bburl']}/member.php?action=register">Not a member yet? Register here</a>
                </span></strong>
                </td>
          </tr>

</table>

</form>

Many thanks
After some searching I found an old post here...

It suggested changing...

<input type="hidden" name="url" value="{$redirect_url}" />

With...

<script type="text/javascript" language="JavaScript"><!--
document.write ("<input type='hidden' name='url' value='"+location.href+"' />")
//--></script>

I won't pretend to know why on this particular template I needed to do this, but it worked for me Big Grin