doubledee Posted July 30, 2011 Share Posted July 30, 2011 I am building a Log-In module and want to be able to return the user to where they came from after logging them in. How can I pass the URL where they were originally at in the URL? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/ Share on other sites More sharing options...
AyKay47 Posted July 30, 2011 Share Posted July 30, 2011 can you show a little of the infrastructure of your code so I have an idea as to what exactly your logic is Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249542 Share on other sites More sharing options...
doubledee Posted July 30, 2011 Author Share Posted July 30, 2011 can you show a little of the infrastructure of your code so I have an idea as to what exactly your logic is I'm not sure I want to do what I'm asking help for now?! Here is the problem I want to solve... A visitor is on Page-1 and wants to do something that requires logging in. I need to capture what and where Page-1 is at, so that after they register, get an account activation e-mail, click on that link, and get a log-in screen, they will then be transferred back to Page-1 so they can pick up where they left off. I am thinking maybe I can just store Page-1 in a $_SESSION and then refer to that later?! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249543 Share on other sites More sharing options...
AyKay47 Posted July 30, 2011 Share Posted July 30, 2011 why not make the login a dynamic include, that way if the user needs to login, a dialog or something of the sorts pops up on whatever page they are on.. Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249545 Share on other sites More sharing options...
doubledee Posted July 30, 2011 Author Share Posted July 30, 2011 why not make the login a dynamic include, that way if the user needs to login, a dialog or something of the sorts pops up on whatever page they are on.. But that doesn't address my question. (And no pop-ups.) Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249547 Share on other sites More sharing options...
AyKay47 Posted July 30, 2011 Share Posted July 30, 2011 but its much more user friendly and makes more sense.. AyKay Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249550 Share on other sites More sharing options...
doubledee Posted July 30, 2011 Author Share Posted July 30, 2011 but its much more user friendly and makes more sense.. AyKay Because that won't work when they aren't a registered member... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249553 Share on other sites More sharing options...
AyKay47 Posted July 30, 2011 Share Posted July 30, 2011 however if you want to do it your way, there might be a way to set a session with the value of $_SERVER['SCRIPT_NAME'] and have it update each time the user jumps to a page that isn't your login page, then when the user needs to login, call the session value that should contain the last page that the user visited... Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249554 Share on other sites More sharing options...
Eiolon Posted July 30, 2011 Share Posted July 30, 2011 $_SERVER['HTTP_REFERRER'] will tell you the URL that you came from. Just make sure you validate it. Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249576 Share on other sites More sharing options...
doubledee Posted July 30, 2011 Author Share Posted July 30, 2011 $_SERVER['HTTP_REFERRER'] will tell you the URL that you came from. Just make sure you validate it. What kinds of things should I do to validate it? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249582 Share on other sites More sharing options...
doubledee Posted July 30, 2011 Author Share Posted July 30, 2011 $_SERVER['HTTP_REFERRER'] will tell you the URL that you came from. Just make sure you validate it. I tried that function but it doesn't work. I get the error: Notice: Undefined index: HTTP_REFERRER in /Users/user1/Documents/DEV/++htdocs/01_MyProject/create_account.php on line 140 From what I Googled, it sounds like this function is unreliable. Is there something that does the same thing but which is more reliable?! Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249583 Share on other sites More sharing options...
phpsycho Posted July 30, 2011 Share Posted July 30, 2011 Why not just have the form action say.. http://site.com/signup.php?gotoafter=currentlink then when you are done signing up, have it redirect you to $_GET['goafter'] EDIT: oops.. the link to signup should be contain the current url and then when you click on it it will send that data to the signup page, from there you can redirect back. Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249587 Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2011 Share Posted July 30, 2011 It's misspelled. It's $_SERVER['HTTP_REFERER']. Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249601 Share on other sites More sharing options...
QuickOldCar Posted July 30, 2011 Share Posted July 30, 2011 lol, was just gonna write that $_SERVER['HTTP_REFERER'] yes referrer is the correct word, but php uses it with referer http://php.net/manual/en/reserved.variables.server.php Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249604 Share on other sites More sharing options...
doubledee Posted July 31, 2011 Author Share Posted July 31, 2011 lol, was just gonna write that $_SERVER['HTTP_REFERER'] yes referrer is the correct word, but php uses it with referer http://php.net/manual/en/reserved.variables.server.php That's retarded! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249629 Share on other sites More sharing options...
doubledee Posted July 31, 2011 Author Share Posted July 31, 2011 It's misspelled. It's $_SERVER['HTTP_REFERER']. I made one step forward but am still having issues re-directing to the original page after logging in. Here is the sequence of events... - Visitor is on "original_page.php" - Visitor clicks "Add a Comment" - System displays a message to "Log In" or "Create an Account" - Visitor chooses "Create an Account" - System displays a "Create an Account" form - Visitor enters Name, Email, and Password - System confirms data - System display a message saying it will send an Activation Link in an e-mail - System sends e-mail - Visitor opens e-mail and clicks on link - Visitor is taken to "activate.php" - System reads E-mail and Activation Code in link and activates account - System displays message for user to click link to "Log In" - Member clicks on link - System displays "Log In" form ("log_in.php") - Member logs in - System reads $_SESSION['referringPage'] and *should* redirect to "original_page.php" In "create_account.php" I have... $_SESSION['referringPage'] = $_SERVER['HTTP_REFERER']; And in "log_in.php" I have... // Check for Member Record. if (mysqli_stmt_num_rows($stmt)==1){ // Member was Found. // Bind result variables. mysqli_stmt_bind_result($stmt, $memberEmail, $memberFirstName); // Fetch record. mysqli_stmt_fetch($stmt); $_SESSION['loggedIn'] = TRUE; $_SESSION['memberEmail'] = $memberEmail; $_SESSION['memberFirstName'] = $memberFirstName; header("Location: " . $_SESSION['referringPage']); // Send and turn off output buffering. ob_end_flush(); // End script. exit(); When I go to log in I get this error... Notice: Undefined index: referringPage in /Users/user1/Documents/DEV/++htdocs/01_MyProject/log_in.php on line 114 Any idea what is going wrong?? Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249633 Share on other sites More sharing options...
AyKay47 Posted July 31, 2011 Share Posted July 31, 2011 Your session isn't getting set. You really should first verify that your server provides this server value. Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249800 Share on other sites More sharing options...
doubledee Posted July 31, 2011 Author Share Posted July 31, 2011 Your session isn't getting set. You really should first verify that your server provides this server value. I accidentally CUT my session code instead of COPYING it to another page?! Oops!! So what do you think about my process flow? It seems like I have things working, but I'm still not sure how it works and appears to users?! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/243297-passing-a-url/#findComment-1249837 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.