Restricting IFRAME access in PHP

2019-02-18 17:11发布

I am creating a small web page using PHP that will be accessed as an IFRAME from a couple of sites. I'm wanting to restrict access to this site to work ONLY within the "approved" sites, and not other sites or accessed directly. Does anyone have any suggestions? Is this even possible? The PHP site will be Apache, and the sites iframing the content will probably be .NET.

Just to clarify, any site can view the page, as long as it's iframe'd within an approved site. I want to block people from accessing it directly. I'm thinking cookies might be a solution, but I'm not sure.

7条回答
别忘想泡老子
2楼-- · 2019-02-18 17:40

I would implement this the same way that google implements adsense. Instead of having them embed the iframe code in their site, instead have them embed some javascript which includes an account number:

<script type="text/javascript"><!--
myiframe_client = "12345";
myiframe_width = 728;
myiframe_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://www.example.com/scripts/show_iframe.js">
</script>

At least this way you can manage who displays your iframe contents on a per-account basis. If somebody unauthorized attempts to use your iframe, you can disable the account. You can also examine properties of the document through javascript (within the security limitations of the browser) to prevent unauthorized access.

查看更多
登录 后发表回答