WordPress网站防止被iframe框架嵌套调用或网页被点击劫持漏洞Frame的9种方法
睿达科网络提供:兰州网站建设/兰州网站制作/兰州网站设计/微信开发/SEO/代运营等服务…… 浏览更多产品服务
1、Meta标签方法:
<meta http-equiv="X-FRAME-OPTIONS" content="DENY">
很多时候受浏览器的影响,不是很管用
2、js方法:
这种方法网上最多,但当对方屏蔽了Js就不可靠了!下面列举了5种Js代码供你参考。
<script type="text/javascript">
if(self != top) { top.location = self.location; }
</script>
<script type="text/javascript">
if(top!=self) {top.location.replace(document.location);}
</script>
<script type="text/javascript">
<!--
if (top.location.href != self.location.href)
top.location.href = self.location.href;
//-->
</script>
<script type="text/javascript">
if(top.location != window.location) {
window.location = '/error_iframe.php';
}
</script>
<script type="text/javascript">
if (window.top !== window.self) window.top.location.replace(window.self.location.href);
</script>
放到你的主题模板header.php文件中的标签前
3、PHP方法:
<?php header(‘X-Frame-Options:Deny'); ?>
放到你的主题模板header.php文件中的标签前
4、Apache主机方法:
Header always append X-Frame-Options SAMEORIGIN
如果有多个站点, 可在Apache主机的httpd.conf文件中加一句后重启生效:
5、.htaccess方法:
如果只是一个站点, 在网站根目录下的.htaccess文件中中加一句:
Header append X-FRAME-OPTIONS "SAMEORIGIN"
6、Nginx主机方法:
在nginx/conf/nginx.conf文件中加一句后重启生效:
add_header X-Frame-Options "SAMEORIGIN";
7、IIS方法:
在web.config文件中加:
<system.webServer>
...
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
...
</system.webServer>
8、wordpress专用:
代码放入到主题 functions.php 文件中
function break_out_of_frames() {
if (!is_preview()) {
echo "\n<script type=\"text/javascript\">";
echo "\n<!--";
echo "\nif (parent.frames.length > 0) { parent.location.href = location.href; }";
echo "\n-->";
echo "\n</script>\n\n";
}
}
add_action('wp_head', 'break_out_of_frames');
9、java代码:
response.addHeader("x-frame-options","SAMEORIGIN");
根据你的网站的实际情况选择适合你的一种方式,希望对你有所帮助。
版权属于:睿达科网络 »《WordPress网站防止被iframe框架嵌套调用或网页被点击劫持漏洞Frame的9种方法》
原文链接:https://www.radartek.com/9-way-to-prevent-wordpress-website-being-displayed-inside-iframe.html
本文采用 「CC BY-NC-SA 4.0」创作共享协议,转载时必须以链接形式注明原始出处及本声明。
如果喜欢本站文章,欢迎点此扫描二维码,关注睿达科网络微信公众服务号
Bewho
技术营销顾问
“HI~感谢关注睿达科网络
如果您想要更多专业指导或深入合作,
可添加我的微信。”
睿达科网络-微信公众服务号
扫描二维码即刻联系我们
marketing@radartek.com