TheEddy Posted August 7, 2010 Share Posted August 7, 2010 I want people to login and then be redirected back to the page from where they came from. I was thinking that maybe I would have to use $_GET for 3 pages but I don't know if there is any easier way. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 7, 2010 Share Posted August 7, 2010 You could use $_SERVER['HTTP_REFERER'], or use sessions to store the previous page URI, then re-direct to that after login. Quote Link to comment Share on other sites More sharing options...
TheEddy Posted August 8, 2010 Author Share Posted August 8, 2010 You could use $_SERVER['HTTP_REFERER'], or use sessions to store the previous page URI, then re-direct to that after login. How does one use the HTTP_REFERER method? Quote Link to comment Share on other sites More sharing options...
sbsads Posted August 8, 2010 Share Posted August 8, 2010 You should echo the $_SERVER['HTTP_REFERER'] variable to see the exact content of the string, but after you process your form, your VERY FIRST HTTP output should come from code like the following: header ('location:http://www.yoursite.com/'.$_SERVER['HTTP_REFERER']); Depending on your site structure, this may work as well: header ('location:your_folder/'.$_SERVER['HTTP_REFERER']); NOTE: $_SERVER['HTTP_REFERER'] will not likely pass variables such as $_GET values, so you may need to manually build a code referral method and use that for the login. here is what I used recently on a site: // sets referral page for login if ($_GET['action'] != 'login') { unset($_SESSION['refer']); foreach ($_GET as $field=>$value) { $bld_refer .= '&'.$field.'='.strip_tags($value); } $_SESSION['refer'] = '?'.ltrim($bld_refer,'&'); } //processes login switch ($get['task']) { case 'logout': $refer = $_SESSION['refer']; $new_user->logout_user(); header('Location:'.$refer); break; case 'login': $vars = new variables($db); $req = $vars->req_fields(); $entries = $new_user->usrLogin($_POST,$req['login']); if (isset($entries['error'])) { $this_form->login_form($entries,$entries); } else { header('Location:'.$_SESSION['refer']); } break; } I do have some classes that process the login, but if the method returns true, it kicks the user to the page the logged in from. Hope that helps Quote Link to comment Share on other sites More sharing options...
TheEddy Posted August 12, 2010 Author Share Posted August 12, 2010 It was better for me to use this: function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $r=curPageURL(); $_SESSION['REFERER']=$r; Because I also needed to record the direct input from the browser. Thanks for your help though! 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.