检查网站是否在iframe内 [英] Check if site is inside iframe

查看:118
本文介绍了检查网站是否在iframe内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道是否可以通过PHP检查网站是否在iframe内。

Anyone know if it's possible to check if a site is inside an iframe with PHP.

我知道可以使用javascript,但我找不到任何示例使用PHP?

I know it's possible with javascript, but i couldn't find any example with PHP?

推荐答案

PHP永远不会出现在iframe中。 PHP在服务器端执行并生成输出,如HTML,Javascript或文本。 PHP生成的输出可能产生或驻留在iframe中,但从不在PHP本身。

PHP is never in an iframe. PHP is executed on the server side and generates output such as HTML, Javascript, or text. The output generated by PHP may produce or reside within an iframe, but never PHP itself.

附加详细信息

关于您在评论中添加的其他详细信息(您希望区分直接访问您网站的请求和通过Facebook应用程序发出的请求),您可以使用的技巧很少:

With regard to the additional detail you added in comments (that you want to distinguish between requests directly to your site and requests via a Facebook application) there are a few techniques you can use:


  1. $ _ SERVER ['HTTP_REFERER']:

  1. $_SERVER['HTTP_REFERER']:

您可以检查推荐人以确定请求来自Facebook网址,来自您自己网站上的其他网页,来自第三方网站,还是来自第三方网站直接交通。此方法并非万无一失,但可能会提供比您当前收到的应用程序更多的信息。

You can check the referrer to determine if a request came from a Facebook URL, from another page on your own site, from a third-party site, or if it was direct traffic. This method is not foolproof, but may provide more information than your application currently receives.


  1. 单独的网址

  1. Separate URLs

您可以为您网站上运行的应用程序和Facebook版本创建单独的URL。使用 $ _ SERVER ['REQUEST_URI'] ,您可以轻松检测您的应用程序是通过'yoursite.com/fbapp'还是'yoursite.com/localapp'访问的。这两个URL都可以通过Apache的mod_rewrite或您选择的别名解决方案引用相同的脚本。

You can create separate URLs for the application running on your site and the Facebook version. Using $_SERVER['REQUEST_URI'], you can easily detect whether your application was accessed via 'yoursite.com/fbapp' or 'yoursite.com/localapp'. Both URLs can reference the same scripts via Apache's mod_rewrite or the aliasing solution of your choice.


  1. URL参数

  1. URL Parameters

此方法可能最容易实现。如果您在向Facebook提供应用程序URL时可以提供URL参数,只需添加参数即可。例如:

This method is possibly the easiest to implement. If you can provide URL parameters when you provide an application URL to Facebook, just add a parameter. For example:

?access_method=facebook

在PHP中,您可以轻松检查 access_method 参数的存在和值,并根据需要采取措施。

In PHP, you can easily check for the existence and value of the access_method parameter, and take action as necessary.

这篇关于检查网站是否在iframe内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆