Hi all, I'm using aMember pro with the phpBB3 plugin. I'm trying to do something that is probably simple but I've been wracking my brain over it for a couple of days and can't think of a solution. Here is my situation: If I am not logged in and I am viewing a forum post and click "Reply" (or do anything in phpBB that requires the user to be logged in), I am taken to the aMember login page. After login, I am directed to the aMember member.php page. What I want is this: When a user who isn't logged in tries to reply to a post (or do anything in phpBB that requires the user to be logged in), they are taken to the aMember login page like they are now. However, after successful login, I want to return the user to the page they were trying to access - in this case, the post that the user was originally trying to reply to. I've been able to replicate this functionality in my other, non-phpBB3 pages in my site by assigning a variable containing the page path and passing it to aMember via a hidden amember_redirect_url form field. However, I haven't been able to figure out how to pass a URL from a forum post (for example, '/forum/viewtopic.php?f=9&t=24') into the amember_redirect_url. Please help! Thanks in advance. John
The problem will be in ? and & signs. So you need to pass urlencoded value in _amember_redirect_url variable. For example: "_amember_redirect_url=".urlencode($_SERVER['REQUEST_URI']);
Thanks for the fast reply, Alexander. Here's where I am still stuck. Hopefully you can tolerate a bit of hand-holding here as I am an intermediate PHP coder with a bit of experience with phpBB3 but am new to aMember. I know that somewhere in the phpBB3 code I will need to put something that saves the current URL to memory so that if the user is trying to access something requiring a login we can pass this to aMember via amember_redirect_url. I also realize that somewhere in the aMember code (most likely login.html), I will need to put something in to "catch" the URL from the above step so that we can redirect the user back to the page within phpBB3 that sent the user to the login page. I guess where I am confused is how we are doing these two steps. My first thought was to write the current url as a session variable on the phpBB3 side and then checking for the session variable on the aMember login page and passing it to amember_redirect_url if it exists. Naturally, this didn't work as I got smarty errors. Can you point me in the right direction? What should I be doing in my phpBB3 code? What should be done in the aMember side? Sorry for the noob questions. I don't expect you to write the code for me, just give me a general idea of what I should be thinking here. As I said before I'm an intermediate coder with a bit of experience with phpBB3 - I'm still new to the aMember code base which is probably why I'm having trouble getting this one bit. Thanks for your help so far! I love this software!
How did you set protection for phpBB? Do you use new_rewrite, or did you modify phpBB templates or code? I need more info about how you redirect user to login when user try to access any pages that should require login.
Thanks for helping me track this issue down Alexander! I'm pretty much using an out-of-the-box installation of phpBB3. In other words, I am using whatever protection method phpBB3 installs by default. The only modifications I made to the phpBB3 code was adding a redirect to the "register" link in ucp.php in phpBB3 as recommended in the aMember phpBB3 plugin instructions so that users are directed to the aMember registration page instead of the phpBB3 registration page. EDIT: I also modified the overall_header.html and overall_footer.html files, although this consisted of keeping the existing phpBB3 code and just adding my styling elements where appropriate to fit my site layout. Additionally, I added similar redirects for the login and logout links in phpBB3 to point to the aMember login page (instead of phpBB's) and to aMember's logout page (instead of phpBB, as using that logout link would log you out of phpBB3 but not aMember). Here is the stretch of code in ucp.php in phpBB3 that I modified. My aMember directory is called "members": Code: case 'register': if ($user->data['is_registered'] || isset($_REQUEST['not_agreed'])) { redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } header("Location: /members/signup.php"); exit(); $module->load('ucp', 'register'); $module->display($user->lang['REGISTER']); break; case 'login': if ($user->data['is_registered']) { redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } header("Location: /members/member.php"); exit(); login_box(request_var('redirect', "index.$phpEx")); break; case 'logout': if ($user->data['user_id'] != ANONYMOUS && isset($_GET['sid']) && !is_array($_GET['sid']) && $_GET['sid'] === $user->session_id) { header("Location: /members/logout.php"); exit(); $user->session_kill(); $user->session_begin(); $message = $user->lang['LOGOUT_REDIRECT']; } else { header("Location: /members/logout.php"); exit(); $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED']; } meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")); $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> '); trigger_error($message); break; So when a user is on a forum page in phpBB3 and clicks "Reply", the code in the "login" case of the above switch statement is triggering the redirect to the aMember login page. The thing I am stuck on is how do we pass along the return url since we are redirecting via a header() redirect in php. Thanks for taking the time to help with this issue! It is much appreciated!
Ok. First of all you need to use redirect to /members/login.php and not to member.php Then you can pass amember_redirect_url via get parameter: PHP: header("Location: /members/login.php?amember_redirect_url=".urlencode($_SERVER['REQUEST_URI'])); exit(); Let me know if this will not help.
Thanks Alexander! That was it! I also found a redirect to aMember's login page in phpBB3's posting.php page when I performed a sitewide find and replace. I added your code there as well, so now everything is redirecting as it should! Thanks again for your help!