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