comments w/membership login redirect

By squeazel - July 12, 2012

I've set up comments and membership. (The only way to sign up or sign in is via comments on a page.) If the user signs in to comment, they are not being returned to the page they were previously on. For the most part, everything is still in its default demo settings.

It looks like this problem was discussed in post 89950, but it's unclear if there was a solution.

Re: [charnushka] comments w/membership login redirect

By Jason - July 13, 2012

Hi,

If you open up your website membership plugin file, you'll probably see this line near the top:

$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'] = '/';

This tells the plugin where to redirect the user after they have successfully logged in. To keep them on the same page, remove the slash:

$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'] = '';

Give that a try and let me know if you run into any problems.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] comments w/membership login redirect

By squeazel - July 14, 2012

I tried that change. Here is what happened:

(1) Go to page with user comments when not logged in. Click login in order to comment.
(2) Taken to user-login page.
(3) Submit username and password.
(4) User login page now says "You are already logged in. Click here to continue, or Logoff." (This seems a little odd... I was hoping for an immediate redirect back to the original page.)
(5) Clicking on "click here to continue" now doesn't take me anywhere. (Before removing the slash it would take me to the root.

thanks!

Re: [charnushka] comments w/membership login redirect

I'm having this same issue - when changing this:
$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'] = '/';
to this:
$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'] = '';

and running through the sames steps as charnuska (minus the comments plugin which I'm not using) the link now directs nowhere, essentially 'working' as you've described - it 'keeps them on the same page' which in this example is the login page.

I'm looking for an immediate redirect back to the original page - the one the user initially clicked on to login. Is this possible? I also couldn't tell if there was ever a solution posted.

Thanks,
Cricket7475

Re: [cricket7475] comments w/membership login redirect

Hi,

I think we've found a solution to the problem.

If you set a URL to lastUrl in the sites cookie a user will be automatically redirected once they have logged in. If you are using the comments system the best place to add this code is in your comments template file where it checks if a user has hasn't logged in. In the default template this is on line 44:

<?php if (!$CURRENT_USER): ?>
<?php setcookie(getCookiePrefix()."lastUrl", thisPageUrl(), time()+(60*5)); ?>
Please <a href="<?php echo $GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL'] ?>">login</a>
or <a href="<?php echo $GLOBALS['WEBSITE_LOGIN_SIGNUP_URL'] ?>">sign-up</a> to add your comment.<br/>
<?php endif ?>
<!-- End: Add your comment -->


You will need to add the line of code that is highlighted in blue above. It will set the current page URL to a variable called lastUrl in the cookie. I have set it to expire after 5 minutes in the above example, so that if the user visits another part of the site and then logs in they will not be automatically taken back to the last comments page they were looking at after 5 minutes. You can alter how long the cookie lasts by changing the 5 to however many minutes you want it to last in the +(60*5) part of the code.

You can also use this line of code on any page that you would like the user to be returned to after they have logged in and not just in the comments plugin. You just need to add it after the viewer functions have been called on any PHP page.

Let me know if you have any problems.

Thanks

Greg
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] comments w/membership login redirect

Hi Greg,

Thanks for the response. So you know what I'm working with: CMS Builder 2.14 and Website Membership Plugin 1.07.

I'm not using the comments plugin, and so attempted to add the code to a test page I've been working on. Got an error message when trying to find the best placement for the snippet you provided. Eventually tried placing it at the very end of my page just before the closing body tag and no more visible errors on the page, but in the source I get the same error (minus actual DB info):

Warning: Cannot modify header information - headers already sent by (output started at /home/.../support-test.php:41) in /home/.../support-test.php on line 348

The line number is the line where the snippet has been inserted and as I moved it up and down in the code that line number would change accordingly. And since the cookie isn't being added my redirect isn't working.

Any ideas?

Thanks!
Cricket7475