acctman Posted August 21, 2008 Share Posted August 21, 2008 is there a way to make sure a user is coming from page1.php when page2.php is loaded and if they're not coming from page1.php redirect them back to page1.php Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/ Share on other sites More sharing options...
Lamez Posted August 21, 2008 Share Posted August 21, 2008 this is very simple: something like this: PAGE 1 <?php session_start(); $_SESSION['page_1'] = true; echo "This is page 1"; echo '<br /><a href="page_2.php">Page 2</a>'; ?> PAGE 2 <?php if (!isset($_SESSION['page_1'])){ header("Location: page_1.php"); }else{ echo "Welcome to page 2!"; } ?> Hope that helps\works Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-621650 Share on other sites More sharing options...
Fadion Posted August 21, 2008 Share Posted August 21, 2008 Try: page 1 <a href="page2.php">Click Me</a> page 2 <?php $referer = pathinfo($_SERVER['HTTP_REFERER'], PATHINFO_BASENAME); if($referer == 'page1.php'){ echo 'You came from the right place'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-621851 Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2008 Share Posted August 21, 2008 Since 'HTTP_REFERER' is a header that is sent with the request for the page, if I was a bot script, I would simply set 'HTTP_REFERER' to be what your script is expecting and I could directly access page2 without ever visiting page1. Using a session variable (something that is completely out of the hands of the visitor or bot script) is the most secure way to do this. The session variable should be unset() after you test it so that once someone (or a bot script) visits page1, they cannot repeatedly perform the action permitted on page2 without needing to go back to page1 to set the session variable again. Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-621886 Share on other sites More sharing options...
Fadion Posted August 21, 2008 Share Posted August 21, 2008 I don't know what the thread starter needs to achieve, but talking about a bot is overwhelming. Even though I support the session method and the snippet I suggested was just an alternative. Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-621999 Share on other sites More sharing options...
Lamez Posted August 21, 2008 Share Posted August 21, 2008 so did I tell him right? this is very simple: something like this: PAGE 1 <?php session_start(); $_SESSION['page_1'] = true; echo "This is page 1"; echo '<br /><a href="page_2.php">Page 2</a>'; ?> PAGE 2 <?php if (!isset($_SESSION['page_1'])){ header("Location: page_1.php"); }else{ echo "Welcome to page 2!"; } unset($_SESSION['page_1']); ?> Hope that helps\works Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-622006 Share on other sites More sharing options...
Fadion Posted August 21, 2008 Share Posted August 21, 2008 lol Lamez. You did Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-622039 Share on other sites More sharing options...
Lamez Posted August 21, 2008 Share Posted August 21, 2008 lol sweet :D Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-622132 Share on other sites More sharing options...
acctman Posted August 21, 2008 Author Share Posted August 21, 2008 so did I tell him right? this is very simple: something like this: PAGE 1 <?php session_start(); $_SESSION['page_1'] = true; echo "This is page 1"; echo '<br /><a href="page_2.php">Page 2</a>'; ?> PAGE 2 <?php if (!isset($_SESSION['page_1'])){ header("Location: page_1.php"); }else{ echo "Welcome to page 2!"; } unset($_SESSION['page_1']); ?> Hope that helps\works thanks. and thanks to everyone who posted. About "unset" when should that be used? unset is new to me Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-622315 Share on other sites More sharing options...
BlueSkyIS Posted August 21, 2008 Share Posted August 21, 2008 About "unset" when should that be used? when you want to unset (destroy) a variable Quote Link to comment https://forums.phpfreaks.com/topic/120637-solved-check-referring-page/#findComment-622384 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.