1

I'm developing a PHP website and it's crucial that some of its webpages, which are user generated, must be not embeddable in an iframe on other domains unless I want to.

Is there a way to accomplish this? I noticed i.e. that Vimeo offers premium users to set a list of domains on which a video can be embedded, so I imagine that this is possible in some ways, despite I haven't found anything around...

Thanks!

Emi-C
  • 3,832
  • 1
  • 15
  • 15

2 Answers2

1

You could include a javascript-code on pages that are not allowed as/in iframes, that redirects the top-frame and the iframe becomes useless in most cases.

if ( window.self !== window.top ) {
    window.top.location.href = window.location.href;
}

Most modern Browsers also respect the header-field X-FRAME-OPTIONS that can be set to DENY (page did not get displayed inside frames) or SAMEORIGIN (same as DENY, but only if the domain is not the same).

Jan
  • 2,853
  • 2
  • 21
  • 26
0

Have a look at the referrer.

if (!in_array($_SERVER['HTTP_REFERER'], $allowedReferers)) {
    // STOP !!!!
    echo "not today baby!";
    die();
}

// GO !!!!
Kevin Nagurski
  • 1,889
  • 11
  • 24