etrader Posted August 29, 2011 Share Posted August 29, 2011 When displaying a webpage within iframe of facebook fan page, how I can detect that my page is viewed within the facebook iframe? I want to have a if else statement to change something within the page if it is viewed through facebook fanpage (not by direct visit). Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/ Share on other sites More sharing options...
Jacbey Posted August 29, 2011 Share Posted August 29, 2011 Here, something like this might work. <?php if (javascript:alert(parent.location.href) == http://www.facebook.com/*name of your webpage*) { //first code here else //else code here ?> Haven't tested it so, I don't know. Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/#findComment-1263121 Share on other sites More sharing options...
xyph Posted August 29, 2011 Share Posted August 29, 2011 This is JavaScript functionality, and not PHP. The post above me is just wrong Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/#findComment-1263167 Share on other sites More sharing options...
etrader Posted August 29, 2011 Author Share Posted August 29, 2011 I hoped to have something like $_SERVER to get the parent of iframe. Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/#findComment-1263256 Share on other sites More sharing options...
KevinM1 Posted August 29, 2011 Share Posted August 29, 2011 I hoped to have something like $_SERVER to get the parent of iframe. How would the server variables associated with your script detect that another script - executing on another server - framed your script? Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/#findComment-1263261 Share on other sites More sharing options...
etrader Posted August 29, 2011 Author Share Posted August 29, 2011 It should be something like agent and getting information about visitors. When my script is accessed through an iframe (here facebook) there should be a difference with the case that the page is directly accessed. I think in the iframe case, facebook is accessing my page, and I should be able to detect facebook as a something like agent. Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/#findComment-1263268 Share on other sites More sharing options...
KevinM1 Posted August 29, 2011 Share Posted August 29, 2011 Except, Facebook isn't an agent, and aside from REQUEST_URI, there isn't anything available to you that could help. Even then, REQUEST_URI may not be reliable. The only sure-fire way to detect if you've been framed is to use JavaScript. http://www.php.net/manual/en/reserved.variables.server.php Quote Link to comment https://forums.phpfreaks.com/topic/245947-how-to-detect-the-parent-of-an-iframe/#findComment-1263313 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.