willc Posted March 10, 2008 Share Posted March 10, 2008 Hi, I have a page/forum that I am basically embedding into my existing website. It's possible to access the page somewhere else by typing in the specific URL of that page. But I only want people to have access to that page if they access it through my website. Is there a way to do this? I'm thinking it's possible to check the URL using PHP and allow access only if the URL is correct, but I'm not sure. Does anyone know how to do this or can offer suggestions? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/ Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 So let me check.. you have a main page ie mydomain.com/welcome.php and mydomain.com/other_section.php and you want people to access other_section.php VIA welcome.php but NOT directly.. if so... you could use sessions/cookies ie <?php session_start(); $_SESSION['access'] = true; ?> <?php session_start(); if ($_SESSION['access'] !== true) { die("No access"); }else{ $_SESSION['access'] = false; //clear so they need to use the welcome.php again } echo "Hello world"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/#findComment-488666 Share on other sites More sharing options...
willc Posted March 10, 2008 Author Share Posted March 10, 2008 Okay, thank you very much. I will give that a try. One important thing I forgot to mention is that there are many pages within this area of the website that I don't want to people to access directly. All of the pages (there are about 20) are in a folder called forum that I don't want people to access directly. Is there a way to provide that kind of solution to the folder (and therefore all of the pages within it) easily or do I need to go into each individual php page and apply that code? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/#findComment-488672 Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 well if its a typical forum 99% of the data is accesed via i file called index.php if you add the code above excluding }else{ $_SESSION['access'] = false; //clear so they need to use the welcome.php again , that should suite quite well, it really depends on the forum and the exact requirments.. of course you could change the boolean (true/false) for a timestamp, this will allow access (including direct access) for a time period (start from when they went to welcome.php) .. if that make sense! so to sum up.. welcome.php sets the time and other_section.php checks the time ie <?php session_start(); $_SESSION['access'] = time(); ?> <?php session_start(); if (time() > $_SESSION['access']+(60*60)) //1 hour { die("No access"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/#findComment-488675 Share on other sites More sharing options...
l0ve2hat3 Posted March 10, 2008 Share Posted March 10, 2008 or you can do <a href='somepage.php?code=specialcode'>somelink</a> and on somepage.php: <? if($_REQUEST['code']!="specialcode"){ echo "CANNOT ACCESS PAGE!"; exit(); } ?> but i like MadTechie's better Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/#findComment-488677 Share on other sites More sharing options...
willc Posted March 10, 2008 Author Share Posted March 10, 2008 Thank you both for your suggestions. The forum is normally accessed through the index.php file - that is correct. I guess what I don't want to happen is for people to access it by "getting smart," by typing in other pages in the forum, like www.mydomain.com/forum/search.php. Because it seemed if they did that, they would be able to bypass this "security" I guess I'm trying to implement. Any thoughts on that? Really what is happening is that I have embedded this forum into a members-only area and I only want members (after they have signed in) to view that forum. So, they would only be able to view www.mydomain.com/forum/index through www.mydomain.com/members/forum/. The forum is phpBB by the way. Thanks again! I appreciate the effort. Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/#findComment-488682 Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 Thank you both for your suggestions. The forum is normally accessed through the index.php file - that is correct. I guess what I don't want to happen is for people to access it by "getting smart," by typing in other pages in the forum, like www.mydomain.com/forum/search.php. Because it seemed if they did that, they would be able to bypass this "security" I guess I'm trying to implement. Any thoughts on that? well it would but most of the feature of the from relie on index.php so it will not function correct. Really what is happening is that I have embedded this forum into a members-only area and I only want members (after they have signed in) to view that forum. So, they would only be able to view www.mydomain.com/forum/index through www.mydomain.com/members/forum/. The forum is phpBB by the way. Thanks again! I appreciate the effort. humm.. phpbb has a permission for members only see here Quote Link to comment https://forums.phpfreaks.com/topic/95457-access-to-a-page-only-from-a-particular-url/#findComment-488696 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.