Forum rules

Please read our Guide to Making Ozzu Tutorials if you would like to submit your own tutorials.

TUTORIAL: PHPBB3 MOD: Login+Redirection

  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post July 28th, 2008, 10:30 pm

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.php

FIND
Code: [ Download ] [ Select ]
    case 'login':
        if ($user->data['is_registered'])
        {
            redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
        }

        login_box(request_var('redirect', "index.$phpEx"));
    break;
  1.     case 'login':
  2.         if ($user->data['is_registered'])
  3.         {
  4.             redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  5.         }
  6.         login_box(request_var('redirect', "index.$phpEx"));
  7.     break;

REPLACE WITH
Code: [ Download ] [ Select ]
 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;
  1.  case 'login':
  2.         $redirect = $_POST['from'];
  3.         if($user->data['is_registered'])
  4.         {
  5.             header("Location: ". append_sid($redirect));
  6.         }
  7.         
  8.         login_box(request_var('redirect', "index.$phpEx"), '', '', '', '', append_sid($redirect));
  9.     break;


Open: includes/functions.php

FIND
Code: [ Download ] [ Select ]
     'T_STYLESHEET_NAME'     => $user->theme['theme_name'],

ADD AFTER
Code: [ Download ] [ Select ]
     'THIS_PAGE'             => str_ireplace('&','&',$_SERVER['REQUEST_URI']),


FIND
Code: [ Download ] [ Select ]
function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true)

REPLACE WITH
Code: [ Download ] [ Select ]
function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true, $redirect = './index.php')


Open: styles/prosilver/template/overall_header.html

FIND
Code: [ Download ] [ Select ]
     <!-- 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>
  1.      <!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH -->
  2.             <div id="search-box">
  3.                 <form action="{U_SEARCH}" method="post" id="search">
  4.                 <fieldset>
  5.                     <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}';" />
  6.                     <input class="button2" value="{L_SEARCH}" type="submit" /><br />
  7.                     <a href="{U_SEARCH}" title="{L_SEARCH_ADV_EXPLAIN}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS}
  8.                 </fieldset>
  9.                 </form>

ADD AFTER
Code: [ Download ] [ Select ]
             <!-- 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>&nbsp;<input type="text" name="username" id="username2" size="20" class="inputbox" title="{L_USERNAME}" /><br />
                        <label for="password2">{L_PASSWORD}:</label>&nbsp;<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 -->
  1.              <!-- IF not S_USER_LOGGED_IN and not S_IS_BOT -->
  2.                 <form method="post" action="{S_LOGIN_ACTION}" class="headerspace">
  3.     
  4.                     <fieldset class="quick-login">
  5.                         <input type="hidden" name="from" value="{THIS_PAGE}" />
  6.                         <label for="username2">{L_USERNAME}:</label>&nbsp;<input type="text" name="username" id="username2" size="20" class="inputbox" title="{L_USERNAME}" /><br />
  7.                         <label for="password2">{L_PASSWORD}:</label>&nbsp;<input type="password" name="password" id="password2" size="20" class="inputbox" title="{L_PASSWORD}" /><br />
  8.                         <!-- IF S_AUTOLOGIN_ENABLED -->
  9.                         <label for="autologin2">{L_LOG_ME_IN} <input type="checkbox" name="autologin" id="autologin2" /></label>
  10.                         <!-- ENDIF -->
  11.                         <input type="submit" name="login" value="{L_LOGIN}" class="button2" />
  12.                     </fieldset>
  13.                 </form>
  14.             <!-- 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:
Code: [ Download ] [ Select ]
<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=### :D )

I added the str_ireplace('&','&amp;',$_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 :D I know it's not a huge mod/improvement but it's a good feature to have.

A MODX is provided on my site :)
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 28th, 2008, 10:30 pm

  • Hiphopnetwork
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Aug 17, 2008
  • Posts: 5
  • Status: Offline

Post August 17th, 2008, 12:16 am

had to sign up and let you know i have been searching for this mod all over the web since my site hosts many different areas and when members log in to the respective areas we like them to stay where they logged in, not be redirected to the main index........

GREAT HELP, i'm going to let you know how this goes.....
  • Hiphopnetwork
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Aug 17, 2008
  • Posts: 5
  • Status: Offline

Post August 17th, 2008, 1:18 am

hmm.....didn't work for me actually man.....i got quite a few different errors, rather than trying to fight it, i did an external login, within my overall header template with this code, seems to work fine.......

Code: [ Download ] [ Select ]
    <form method="post" action="http://www.hiphopnetwork.net/forums/ucp.php?mode=login">

<p><font color="black"><b>Username:</font><input name="username" type="text" id="username" />
<font color="black">Password :</font><input name="password" type="password" id="password" /><br />
<font color="black">Log In Here To Go Directly To BeatLiquidators Forums</font></b>

<input name="redirect" value="http://www.hiphopnetwork.net/forums/viewforum.php?f=90" type="hidden">

<input name="login" class="mainoption" value="Log in" type="submit"></p>

</form>
  1.     <form method="post" action="http://www.hiphopnetwork.net/forums/ucp.php?mode=login">
  2. <p><font color="black"><b>Username:</font><input name="username" type="text" id="username" />
  3. <font color="black">Password :</font><input name="password" type="password" id="password" /><br />
  4. <font color="black">Log In Here To Go Directly To BeatLiquidators Forums</font></b>
  5. <input name="redirect" value="http://www.hiphopnetwork.net/forums/viewforum.php?f=90" type="hidden">
  6. <input name="login" class="mainoption" value="Log in" type="submit"></p>
  7. </form>
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post August 19th, 2008, 8:22 pm

Sorry, that it didn't work for you. I forgot to mention that the form action may not be defined in every page so you could use the full URL to the login process page (http://www.site.com/forum/ucp.php?mode=login)

If that doesn't help... what kind of errors do you get?
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • congminh1709
  • Born
  • Born
  • No Avatar
  • Joined: Aug 30, 2008
  • Posts: 1
  • Status: Offline

Post August 30th, 2008, 11:55 pm

Thank you for posting this topic, but i dont use prosilver style, i am using this style: hestia_blue which is downloaded from http://www.stsoftware.biz
So that, how to edit its overall_header.html ?
  • neversummer
  • Born
  • Born
  • No Avatar
  • Joined: Jun 11, 2009
  • Posts: 1
  • Status: Offline

Post June 11th, 2009, 2:01 am

i got this error.... And when i read the explanation it said that you dont really need it, so i commented it out and i didnt get any errors.

Fatal error: Call to undefined function: str_ireplace() in /nfs/c01/h07/mnt/37398/domains/robikrecordings.com/html/forum/includes/functions.php on line 3753

I then built a login script that looked something like this. This works, but it takes me to the "you have succefully logged in page and then bumps me onto the normal index of the forum??
Code: [ Download ] [ Select ]
 
if ($user->data['user_id'] == ANONYMOUS){
                       echo '<form method="POST" action="../forum/ucp.php?mode=login">
                        <br>Username: <input type="text" name="username" size="40">
                        <br>Password: <input type="password" name="password" size="40">
                        <br>Remember Me?: <input type="checkbox" name="autologin">
                        <br><input type="submit" value="Submit" name="login"><br>
                        <input type="hidden" name="from" value="index.php" />
                    </form>';
                    }else{
                       echo 'Thanks for logging in, ' . $user->data['username_clean'];
                    } //end if logged in
 
  1.  
  2. if ($user->data['user_id'] == ANONYMOUS){
  3.                        echo '<form method="POST" action="../forum/ucp.php?mode=login">
  4.                         <br>Username: <input type="text" name="username" size="40">
  5.                         <br>Password: <input type="password" name="password" size="40">
  6.                         <br>Remember Me?: <input type="checkbox" name="autologin">
  7.                         <br><input type="submit" value="Submit" name="login"><br>
  8.                         <input type="hidden" name="from" value="index.php" />
  9.                     </form>';
  10.                     }else{
  11.                        echo 'Thanks for logging in, ' . $user->data['username_clean'];
  12.                     } //end if logged in
  13.  


But then if i logout in the forums screen, and then go to log back in, it says i have succesfully logged in and then redirects me back into the login screen???

the code that Hiphopnetwork put up works great, now i just need to figure out how to skip the "you have succesfully logged in page"
  • mrose
  • Born
  • Born
  • No Avatar
  • Joined: Jun 16, 2009
  • Posts: 1
  • Status: Offline

Post June 17th, 2009, 1:24 pm

is this supported anymore? I think this is what I need, but I need it to redirect outside of the forum domain, but in the same virtual directory. I implemented it and it does redirect, but it still uses the same domain name and puts a % instead of a ? with the sid
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post June 20th, 2009, 11:55 am

I'm pretty sure it is supported, but it could have changed for the updated phpBB Forum. I think I made this mod for 3.0.2 (And current is 3.0.6?)

Also, for those of you who are using different styles, all you need to do in the overall_header.html is add the following form element into the login form.
Code: [ Download ] [ Select ]
<input type="hidden" name="from" value="{THIS_PAGE}" />
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post Information

  • Total Posts in this topic: 8 posts
  • Moderator: Tutorial Writers
  • Users browsing this forum: No registered users and 1 guest
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.