授予构建我的网站的权限

时间:2013-05-20 12:56:15

标签: php url iframe

我通过iframe分享我的网站块。 现在,我需要允许一些特定的域来构建我的网站。其他人将被拒绝。

我怎么能用PHP做到这一点?

提前致谢。

3 个答案:

答案 0 :(得分:1)

您可以发送X-Frame-Options标头,以限制哪些人可以使用框架链接到此网站。

<?php
header('X-Frame-Options: ALLOW-FROM <the domain here>');
?>

您可以在要执行此操作的所有PHP脚本中包含此脚本。 (请务必将<the domain here>更改为您希望它能够使用框架链接到您网站的域名。)

参考:MDN

答案 1 :(得分:0)

在iframe中添加代码

<script language="javascript">
try
{
    // get the location of the parent window
    var p = window.parent.location;

//You can set an array of permitted sites and check if the parent location is not in
 the array then restrict it
   if(p.indexOf('your permitted site domain') <= -1) {
     var str = new String(p);
   }
}
catch (e)
{
    window.location = 'http://yoursite.com';
}
</script> 

答案 2 :(得分:-2)

使用PHP,你可以拥有它......

if($_SERVER[HTTP_REFERER] == 'http://domain.com/page.html') {"The HTML of the page"}
相关问题