Rokboy Posted September 17, 2010 Share Posted September 17, 2010 I'm pretty new to php... I need a short script that I can place at the top of my web page that does the following: In theory, a person only be able to access page2.php unless they come directly from page1.php (The message that appear should say you are not authorized to access this page) I do not want to create login of any kind... Can you help? thanx in advance! Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted September 17, 2010 Share Posted September 17, 2010 Get referral page <?php$ref = $_SERVER['HTTP_REFERER']; $exp = end(explode("/", $ref));if($exp == "index1.php"){echo "Show Content";} else {echo "No Direct Access!";}?> Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 17, 2010 Share Posted September 17, 2010 You can use the HTTP_REFERER variable but be aware that this can be forged easily. I'd do it this way with a session variable instead.... Add this to all pages: session_start();$lastPage = isset($_SESSION['page']) ? $_SESSION['page'] : '';$currentPage = basename($_SERVER['SCRIPT_NAME']);$_SESSION['page'] = $currentPage;if($currentPage == 'page2.php'){ // this is page2, set the $hasAccess variable $hasAccess = $lastPage == 'page1.php' ? true : false; } in page2.php use the $hasAccess variable to check whether or not to display the message <!-- include php script as above --><html><body><?php if(!$hasAccess): ?><p>No access!</p><?php else: ?><p>Welcome to page2...</p><?php endif; ?></body></html> Quote Link to comment Share on other sites More sharing options...
Rokboy Posted September 18, 2010 Author Share Posted September 18, 2010 wow guys, thanks so much for helping out. This was amazingly quick. i'm gonna try to implement the suggestions. Will keep you posted. Cheers. Quote Link to comment Share on other sites More sharing options...
Username: Posted September 18, 2010 Share Posted September 18, 2010 wow guys, thanks so much for helping out. This was amazingly quick. i'm gonna try to implement the suggestions. Will keep you posted. Cheers. 'cause it's amazingly easy once you have an understanding of some basic things in PHP You should mark this topic as solved, that's why I am here 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.