doubledee Posted August 1, 2011 Share Posted August 1, 2011 How do you handle redirecting pages? I am working on a module where people can add comments to an article, but the redirecting logic isn't as easy as it seems. (And if I think about the redirecting logic for my entire website it gets even trickier?!) With this current module... To add a comment, you must be a logged in Member, so that either means you have to "Create an Account" or "Log In". Here are two scenarios: Scenario #1: Visitor A Visitor is on "article1234.php" and wants to add a comment. The path they take goes... "article1234.php" to "create_account.php" (display) to "create_account.php" (post) to email to "activate.php" to "log_in.php" (display) to "log_in.php" (post) to "article1234.php" Scenario #2: Member Not Logged In A Member - who is not logged in - is on "article1234.php" and wants to add a comment. The path they take goes... "article1234.php" to "log_in.php" (display) to "log_in.php" (post) to "article1234.php" I was able to get away using $_SESSION['referringPage'] = $_SERVER['HTTP_REFERER']; in Scenario #2, but that won't easily work for Scenario #1. The problem is that sometimes a redirect is just to where you were just at, and other times it is several steps back to where you were in the past. It is almost as if you need a "Redirect Lookup Table"?! Follow me? Debbie Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted August 1, 2011 Share Posted August 1, 2011 You could set a $_SESSION['cache_post'] variable using a hidden field in your "post comment" form, hold that through to the end of sign up/in and then call it with an if exists contitional at the point of final log in. I'm curious though, how does your system differentiate between a looged out member and a new user? Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 1, 2011 Share Posted August 1, 2011 article1234.php -> session start [page name] -> create_account.php -> create_account.php -> activate.php -> log_in.php -> session [page name] ? article1234.php: home.php (unset (session [page name]) Or use page name cookies Quote Link to comment Share on other sites More sharing options...
the182guy Posted August 1, 2011 Share Posted August 1, 2011 I've never seen a site that accomodates scenario #1. Scenario #2 can be done with a simple session variable storing the article ID. On login, check for the variable and clear it, then redirect to the article. If you must cater for scenario #1 then the same can be used but you need to make sure you don't end up redirecting people that didn't want to be redirected. It depends on how your comment system works i.e does it shown the comment form to guests, then when posting takes them to login, or does it hide the form for guests and they have to click login/create account. Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 2, 2011 Share Posted August 2, 2011 Scenario #1: Visitor have sort the code? if so, can you please tell us what method you have used. Quote Link to comment Share on other sites More sharing options...
doubledee Posted August 3, 2011 Author Share Posted August 3, 2011 You could set a $_SESSION['cache_post'] variable using a hidden field in your "post comment" form, hold that through to the end of sign up/in and then call it with an if exists contitional at the point of final log in. I'm curious though, how does your system differentiate between a looged out member and a new user? Any article would check if $_SESSION['loggedIn'] == TRUE{ Debbie Quote Link to comment Share on other sites More sharing options...
doubledee Posted August 3, 2011 Author Share Posted August 3, 2011 I've never seen a site that accomodates scenario #1. Oh, I think it's pretty common. It depends on how your comment system works i.e does it shown the comment form to guests, then when posting takes them to login, or does it hide the form for guests and they have to click login/create account. There is an article. Below it is a Comments area. In the Comments header is, "What do you think?" followed by either an "Add a Comment" button if the user is a Member and logged in, OR a message, "To add a comment, you must either 'Log In' (button) or 'Create an Account' (button)" for users that are not logged in or visitors. If you aren't logged in, you can't add a comment because there is no button even though the comment field is below. Make sense? Debbie Quote Link to comment Share on other sites More sharing options...
xyph Posted August 3, 2011 Share Posted August 3, 2011 You didn't read his post correctly. @Funster - The new user would visit the signup page, rather than the login page. The only issue with using sessions is it won't always be consistent. If the user has two tabs open, one tab might change session variables that the other relies on. Besides that, it's a great way to track it. Personally, I'd just pass it in the query string article1234.php -> login.php?ref= article1234 -> login.php?ref=article1234 -> if ($_GET['ref']) { redirect } Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 3, 2011 Share Posted August 3, 2011 Yes xyph, yor are correct, I am using this method and session. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted August 3, 2011 Share Posted August 3, 2011 @Funster - The new user would visit the signup page, rather than the login page. I'm confused. What was that statement in regard to? I asked how the site it's self could be aware and differentiate between members who were not logged in and strangers who did not have an account. I'm not asking how it handles each group. ...I'd just pass it in the query string I assume you are actualy talking about the URL? Quote Link to comment Share on other sites More sharing options...
xyph Posted August 3, 2011 Share Posted August 3, 2011 http://en.wikipedia.org/wiki/Query_string Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.