phplearner2008 Posted February 11, 2009 Share Posted February 11, 2009 Hi all, I want php files in my web site to be accessed through links only and not by typing the url directly. How can I do it? Thanks Link to comment https://forums.phpfreaks.com/topic/144735-how-to-prevent-direct-access-of-web-page-by-typing-url/ Share on other sites More sharing options...
btherl Posted February 11, 2009 Share Posted February 11, 2009 You can do a simple (and easily bypassable) attempt by checking to see if $_SERVER['HTTP_REFERER'] is set. Typically that value is set when a link is followed, but not when it's typed in. This method is however easily bypassed by someone who wants to bypass it. A better answer is you can use sessions to track your user, and remember where they are allowed to go. Then you can tell them "Sorry, you can only access this page from this other page, and my session data says you didn't". Link to comment https://forums.phpfreaks.com/topic/144735-how-to-prevent-direct-access-of-web-page-by-typing-url/#findComment-759481 Share on other sites More sharing options...
phplearner2008 Posted February 11, 2009 Author Share Posted February 11, 2009 btherl, can you expand on your second suggestion using sessions? Link to comment https://forums.phpfreaks.com/topic/144735-how-to-prevent-direct-access-of-web-page-by-typing-url/#findComment-759485 Share on other sites More sharing options...
btherl Posted February 11, 2009 Share Posted February 11, 2009 Are you familiar with sessions? Assuming you are, let's say you want someone to access page B only from page A. When they access page A, you store a value in the session like $_SESSION['lastpage'] = 'A'. Then when they access page B, you can check if $_SESSION['lastpage'] is set to A. If you are concerned about users passing data as arguments to the page, then you should store that data on the server instead. Link to comment https://forums.phpfreaks.com/topic/144735-how-to-prevent-direct-access-of-web-page-by-typing-url/#findComment-759500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.