MyBB Community Forums

Full Version: redirect to previous page after logging in
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
it because of theme
default theme works with no problem
im trying to figure this out
Try reverting member_login to orginal.

Admin CP -> Templates & Style -> Templates -> Your Theme -> Member Templates -> member_login -> Options -> Revert to Original.
didn't work
Which theme are you using? I will try it out on my localhost and tell you what I find.
ok i found the problem but dunno how to fix it
its because of Theme's header_welcomeblock_guest template
in default we have
<script type="text/javascript">
<!--
	lang.username = "{$lang->login_username}";
	lang.password = "{$lang->login_password}";
	lang.login = "{$lang->login}";
	lang.lost_password = " &mdash; <a href=\"{$mybb->settings['bburl']}/member.php?action=lostpw\">{$lang->lost_password}<\/a>";
	lang.register_url = " &mdash; <a href=\"{$mybb->settings['bburl']}/member.php?action=register\">{$lang->welcome_register}<\/a>";
	lang.remember_me = "{$lang->remember_me}";
// -->
</script>
<span style="float: right;">{$lang->welcome_current_time}</span>
		<span id="quick_login">{$lang->welcome_guest} (<a href="{$mybb->settings['bburl']}/member.php?action=login" onclick="MyBB.quickLogin(); return false;">{$lang->welcome_login}</a> &mdash; <a href="{$mybb->settings['bburl']}/member.php?action=register">{$lang->welcome_register}</a>)</span>

Which use j-script i think

and in my header_welcomeblock_guest

<div id="memberbar">
<span style="float: left; margin-left: 10px; margin-top: -1px;">

<form action="member.php" method="post">

<input type="text" class="textbox" name="username" value="Username" size="20" onfocus="if(this.value == 'Username') { this.value = ''; }" onblur="if(this.value=='') { this.value='Username'; }" />

<input type="password" class="textbox" name="password" value="password" onfocus="if(this.value == 'password') { this.value = ''; }" onblur="if(this.value=='') { this.value='password'; }" size="20"/>

&nbsp; <label title="{$lang->remember_me_desc}"><input type="checkbox" class="checkbox" name="remember" checked="checked" value="yes" style="vertical-align: middle; margin-top: -1px;" /> {$lang->remember_me}</label>

<span style="margin-left: 8px;">
<input type="submit" class="button" name="submit" value="{$lang->login}" />
<input type="hidden" name="action" value="do_login" />
<input type="hidden" name="url" value="{$redirect_url}" />
</span>

</form>

</span>

<span style="float: right; font-weight: bold; margin-top: 2px; margin-right: 10px;">

<img class="icon" src="{$theme['imgdir']}/key.png" alt="" /><a href="{$mybb->settings['bburl']}/member.php?action=lostpw">{$lang->lost_password}</a>

&nbsp; - &nbsp;

<img class="icon" src="{$theme['imgdir']}/register.png" alt="" /><a href="{$mybb->settings['bburl']}/member.php?action=register">{$lang->welcome_register}</a>

</span>
</div>
Try replacing it with this:

<div id="memberbar">
<span style="float: left; margin-left: 10px; margin-top: -1px;">

<form action="member.php" method="post">

<input type="text" class="textbox" name="username" value="Username" size="20" onfocus="if(this.value == 'Username') { this.value = ''; }" onblur="if(this.value=='') { this.value='Username'; }" />

<input type="password" class="textbox" name="password" value="password" onfocus="if(this.value == 'password') { this.value = ''; }" onblur="if(this.value=='') { this.value='password'; }" size="20"/>

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

&nbsp; <label title="{$lang->remember_me_desc}"><input type="checkbox" class="checkbox" name="remember" checked="checked" value="yes" style="vertical-align: middle; margin-top: -1px;" /> {$lang->remember_me}</label>

<span style="margin-left: 8px;">
<input type="submit" class="button" name="submit" value="{$lang->login}" />
<input type="hidden" name="action" value="do_login" />
<input type="hidden" name="url" value="{$redirect_url}" />
</span>

</form>

</span>

<span style="float: right; font-weight: bold; margin-top: 2px; margin-right: 10px;">

<img class="icon" src="{$theme['imgdir']}/key.png" alt="" /><a href="{$mybb->settings['bburl']}/member.php?action=lostpw">{$lang->lost_password}</a>

&nbsp; - &nbsp;

<img class="icon" src="{$theme['imgdir']}/register.png" alt="" /><a href="{$mybb->settings['bburl']}/member.php?action=register">{$lang->welcome_register}</a>

</span>
</div> 
your code is same as mine Toungue
for making sure i replaced but didn't help
so i looked at the general.js and found how with default theme we can logging normally

it does with this j-script code :

			if(document.location.href)
			{
				form.insert({ bottom: new Element("input",
					{
						name: "url",
						type: "hidden",
						value: this.HTMLchars(document.location.href)
					})
				});
			}

anyone knows how can i make a html code which works like this j-script code?


after wasting 3 and half hours i replaced the default header_welcomeblock_guest template in my theme's header_welcomeblock_guest template template, i found that even default template doesn't work properly with my portal.php (after clicking on "login" , boxes doesn't appear.instead it redirects me to login page)
probably because of using some jQuery in portal.php

so i replaced the old one and users will have some fun with logging in Big Grin

i hate wasting my time for nothing Sad
I had the same problem. After several hours searching for a solution, I finally wrote this short code and works fine

You have to replace this code:

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

with this both in welcomeblock guest and error nopermisson:

<script type="text/javascript" language="JavaScript"><!--
document.write ("<input type='hidden' name='url' value='"+location.href+"' />")
//--></script>
OMG worked where have you been before Big Grin
thank you so much

before i tried this code: <input type='hidden' name='url' value='"<script type="text/javascript" language="JavaScript">+location.href+"' /></script> and didnt worked,im not good in java script Big Grin
but your worked perfectly thanks again
happy to see it worked for you,

Extra: I finally found the way to redirect users to where they were after registering. I use a plugin to hide urls from guests and encouraging them to register. And people need to register to download attachments on the forum. This feature will be very useful this way. Without this, they were being redirected to index.php. But now, directly to the thread page or attachment.

Im still on 1.2.14 and doing partial upgrades myself. So I'm gonna write the changes but the codes maybe differ from 1.2 to 1.6

member.php

if($mybb->input['action'] == "register")
{
	if((!isset($mybb->input['agree']) && !isset($mybb->input['regsubmit'])) || $mybb->request_method != "post")
	{
		$plugins->run_hooks("member_register_agreement");
		eval("\$agreement = \"".$templates->get("member_register_agreement")."\";");
		output_page($agreement);
	}
	else
	{
		$plugins->run_hooks("member_register_start");

After this code

add:
		$redir = htmlentities($mybb->input['redir']);

Find:
redirect("index.php", $lang->redirect_registered);

Replace with:
redirect($mybb->input['redir'], $lang->redirect_registered);

Now we will update templates

member_register
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
After this

Add:
<input type="hidden" name="redir" value="{$redir}" />

member_register_agreement
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
After this

Add:
<script type="text/javascript" language="JavaScript"><!--
document.write ("<input type='hidden' name='redir' value='"+document.referrer+"' />")
//--></script>

If this is useful you can share it (and the login one) on the forums with a new thread so more people can use it. I dont have enough time Toungue
my forum has over 475K+ users now. thats why these are important for me Smile
Pages: 1 2 3