turpentyne Posted March 24, 2012 Share Posted March 24, 2012 is it possible to have a script that changes header based on what page the user came from. something like if ($_SERVER['HTTP_REFERER']) == http://www.site.com/pagebefore.php) { // do nothing, letting page generate } else { header("Location: back_to_the_start_buddy.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/ Share on other sites More sharing options...
dragon_sa Posted March 24, 2012 Share Posted March 24, 2012 Is there a specific page before or could there be many different page allowed to come from? It is possible to do Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330625 Share on other sites More sharing options...
turpentyne Posted March 24, 2012 Author Share Posted March 24, 2012 it would be a specific page before. its the only one I want people to access this page from. (This is a page to enter credit card data and then goes to a confirmation or failed page) I don't want a back button to take them to the page again. Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330634 Share on other sites More sharing options...
teng84 Posted March 24, 2012 Share Posted March 24, 2012 the code above is correct whats the issue with that? Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330637 Share on other sites More sharing options...
dragon_sa Posted March 24, 2012 Share Posted March 24, 2012 The only thing I would change is the way you did it, but your code is right, more like this if ($_SERVER['HTTP_REFERER']) != 'http://www.site.com/pagebefore.php') { header("Location: back_to_the_start_buddy.php"); exit; } // continue to process page Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330641 Share on other sites More sharing options...
turpentyne Posted March 24, 2012 Author Share Posted March 24, 2012 hah! Seriously??? I just typed that to get the point across! I assumed it wouldn't be that easy. I'll try it Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330677 Share on other sites More sharing options...
dragon_sa Posted March 24, 2012 Share Posted March 24, 2012 also remove the extra bracket after $_SERVER['HTTP_REFERER'] , I accidentally copied that in from your code Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330681 Share on other sites More sharing options...
turpentyne Posted March 24, 2012 Author Share Posted March 24, 2012 dang! Not that easy after all. It redirects if I try to just load the page, but if I hit the back button, it'll load the page again. I don't want that. I'm using session to pass info and do have each page caching for 7 minutes, I took that out on the page in question, no difference. It just gives me the warning about reloading the page. Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330790 Share on other sites More sharing options...
dragon_sa Posted March 25, 2012 Share Posted March 25, 2012 You could set a page session and change the session to be page specific for each page, then check for it on each step. On firstpage $_SESSION['page'] = 2; Second page if ($_SESSION['page'] != 2) { header("Location: firstpage.php"); exit; } $_SESSION['page'] = 3; Third page if ($_SESSION['page'] != 3) { header("Location: firstpage.php"); exit; } $_SESSION['page'] = 4; Last page if ($_SESSION['page'] != 4) { header("Location: firstpage.php"); exit; } unset($_SESSION['page']); If they hit back, it will redirect to the firstpage Quote Link to comment https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/#findComment-1330850 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.