phpBb3 Login+Redirection Mod
Mod Version: v1.0.0
Mod Description: When the user logs in on a page, this mod would redirect that user to the page the user logged in from.
Difficulty: Very extremely easy
Estimated Time: ~1 Minute
Files to edit
ucp.php
includes/functions.php,
styles/prosilver/template/overall_header.html
* NO FILES TO INCLUDE *
Actions to perform
Open: ucp.phpFIND
case 'login':
if ($user->data['is_registered'])
{
redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}
login_box(request_var('redirect', "index.$phpEx"));
break;
- case 'login':
- if ($user->data['is_registered'])
- {
- redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
- }
- login_box(request_var('redirect', "index.$phpEx"));
- break;
REPLACE WITH
case 'login':
$redirect = $_POST['from'];
if($user->data['is_registered'])
{
header("Location: ". append_sid($redirect));
}
login_box(request_var('redirect', "index.$phpEx"), '', '', '', '', append_sid($redirect));
break;
- case 'login':
- $redirect = $_POST['from'];
- if($user->data['is_registered'])
- {
- header("Location: ". append_sid($redirect));
- }
-
- login_box(request_var('redirect', "index.$phpEx"), '', '', '', '', append_sid($redirect));
- break;
Open: includes/functions.phpFIND
'T_STYLESHEET_NAME' => $user->theme['theme_name'],
ADD AFTER
'THIS_PAGE' => str_ireplace('&','&',$_SERVER['REQUEST_URI']),
FIND
function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true)
REPLACE WITH
function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true, $redirect = './index.php')
Open: styles/prosilver/template/overall_header.htmlFIND
<!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH -->
<div id="search-box">
<form action="{U_SEARCH}" method="post" id="search">
<fieldset>
<input name="keywords" id="keywords" type="text" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search" value="<!-- IF SEARCH_WORDS-->{SEARCH_WORDS}<!-- ELSE -->{L_SEARCH_MINI}<!-- ENDIF -->" onclick="if(this.value=='{LA_SEARCH_MINI}')this.value='';" onblur="if(this.value=='')this.value='{LA_SEARCH_MINI}';" />
<input class="button2" value="{L_SEARCH}" type="submit" /><br />
<a href="{U_SEARCH}" title="{L_SEARCH_ADV_EXPLAIN}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS}
</fieldset>
</form>
- <!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH -->
- <div id="search-box">
- <form action="{U_SEARCH}" method="post" id="search">
- <fieldset>
- <input name="keywords" id="keywords" type="text" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search" value="<!-- IF SEARCH_WORDS-->{SEARCH_WORDS}<!-- ELSE -->{L_SEARCH_MINI}<!-- ENDIF -->" onclick="if(this.value=='{LA_SEARCH_MINI}')this.value='';" onblur="if(this.value=='')this.value='{LA_SEARCH_MINI}';" />
- <input class="button2" value="{L_SEARCH}" type="submit" /><br />
- <a href="{U_SEARCH}" title="{L_SEARCH_ADV_EXPLAIN}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS}
- </fieldset>
- </form>
ADD AFTER
<!-- IF not S_USER_LOGGED_IN and not S_IS_BOT -->
<form method="post" action="{S_LOGIN_ACTION}" class="headerspace">
<fieldset class="quick-login">
<input type="hidden" name="from" value="{THIS_PAGE}" />
<label for="username2">{L_USERNAME}:</label> <input type="text" name="username" id="username2" size="20" class="inputbox" title="{L_USERNAME}" /><br />
<label for="password2">{L_PASSWORD}:</label> <input type="password" name="password" id="password2" size="20" class="inputbox" title="{L_PASSWORD}" /><br />
<!-- IF S_AUTOLOGIN_ENABLED -->
<label for="autologin2">{L_LOG_ME_IN} <input type="checkbox" name="autologin" id="autologin2" /></label>
<!-- ENDIF -->
<input type="submit" name="login" value="{L_LOGIN}" class="button2" />
</fieldset>
</form>
<!-- ENDIF -->
- <!-- IF not S_USER_LOGGED_IN and not S_IS_BOT -->
- <form method="post" action="{S_LOGIN_ACTION}" class="headerspace">
-
- <fieldset class="quick-login">
- <input type="hidden" name="from" value="{THIS_PAGE}" />
- <label for="username2">{L_USERNAME}:</label> <input type="text" name="username" id="username2" size="20" class="inputbox" title="{L_USERNAME}" /><br />
- <label for="password2">{L_PASSWORD}:</label> <input type="password" name="password" id="password2" size="20" class="inputbox" title="{L_PASSWORD}" /><br />
- <!-- IF S_AUTOLOGIN_ENABLED -->
- <label for="autologin2">{L_LOG_ME_IN} <input type="checkbox" name="autologin" id="autologin2" /></label>
- <!-- ENDIF -->
- <input type="submit" name="login" value="{L_LOGIN}" class="button2" />
- </fieldset>
- </form>
- <!-- ENDIF -->
More Advanced Instructions
Or, instead of adding the login form like I have shown above you just add the following required field in your own login form:
<input type="hidden" name="from" value="{THIS_PAGE}" />
Explanation
This mod/hack uses $_SERVER['REQUEST_URI'] to get the current page's full address. This is so, that the address includes the ?page=#&p=#&t=# in the viewtopic.php or ?f=# in viewforum.php and all those other $_GET variables.
Don't worry about /^[\?|\&]+[sid\=]+[0-9]$/ ... (page.php?sid=### or page.php$f=#$sid=###

)
I added the str_ireplace('&','&',$_SERVER['REQUEST_URI'] in there to keep the validity of the forum pages in case it happens to have a ?f=#&t=#
Conclusion
Hope that this mod works for you and that you are happy with it

I know it's not a huge mod/improvement but it's a good feature to have.
A MODX is provided
on my site 