Anyone know if it's possible to check if a site is inside an iframe with PHP.
I know it's possible with javascript, but i couldn't find any example with PHP?
Embedding webpages using an IFrame. An IFrame is HTML code that you can use to embed one HTML page, PDF page, another website, or other web safe file into a another webpage inside a window. The window can be styled using css code. IFrames do not make a website a "framed" site and do not affect SEO.
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.
ADDITIONAL DETAIL
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:
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.
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.
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
In PHP, you can easily check for the existence and value of the access_method
parameter, and take action as necessary.
For anyone who lands on this old thread: There is a very easy way to check in PHP wether or not your page is loaded through an iframe.
if( isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'iframe' ) {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With