Prodigal Son Posted September 17, 2008 Share Posted September 17, 2008 Does anyone know how to disallow access to a page by a direct url, but allow an iframe src to be able to access the page? i.e. I try to load test.php and I won't be able to access the page, but if I load the page through an iframe, it will work fine. Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 I suggest adding something that looks at the $_SERVER['HTTP_REFERER'] variable. If that's not the page that has the iframe, kill the app. Otherwise let it run. Like this: <?php if ($_SERVER['HTTP_REFERER']!="pagewithiframe.php") die("This page cannot be loaded directly"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/#findComment-643829 Share on other sites More sharing options...
Prodigal Son Posted September 17, 2008 Author Share Posted September 17, 2008 I suggest adding something that looks at the $_SERVER['HTTP_REFERER'] variable. If that's not the page that has the iframe, kill the app. Otherwise let it run. Like this: <?php if ($_SERVER['HTTP_REFERER']!="pagewithiframe.php") die("This page cannot be loaded directly"); ?> Hmm, my pages are dynamic, so never know what the url can be. Should I do a strpos to check if my domain is in the HTTP_REFERER? Or maybe a better way? Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/#findComment-643845 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 That would be my next suggestion. You should be able to find something helpful with the $_SERVER variable. http://us.php.net/manual/en/reserved.variables.server.php Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/#findComment-643849 Share on other sites More sharing options...
Prodigal Son Posted September 17, 2008 Author Share Posted September 17, 2008 Hmm, doesn't seem to be working. When I do a var_dump on the $_SERVER['HTTP_REFERER'] variable (on the iframe page) I get a null. Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/#findComment-643970 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Hmm... Try it on just the $_SERVER variable, or try print_r($_SERVER); and see if there's anything of use to you. Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/#findComment-643977 Share on other sites More sharing options...
Zane Posted September 17, 2008 Share Posted September 17, 2008 you could set a $_SESSION variable for the page. a simple true or false variable that is defined on the parent page..containing the iframe. and then on the iframe you'll probably have to check, destroy, etc the session and what not to keep someone from loading that php file later on. Quote Link to comment https://forums.phpfreaks.com/topic/124656-disallowing-direct-url/#findComment-643981 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.