Prevent Embedding Web Page Inside An Iframe?

by 5 replies
9
How to prevent my site page to be loaded via 3rd party site frame of iframe through php?
I do have javascript ready but I need a php solution.
#programming #embedding #iframe #inside #page #prevent #web
  • This is a client-side thing so PHP won't be able to do anything with it. You'll have to stick with your JavaScript solution.
  • Ok, but I think we can get domain name while loading the page through php. Although, I can't recall the function.

    If we can do that the rest all is simple.
  • Way of preventing your site from being 'taken' by other site. (URL Masking)

    First is the javascript solution, put this code in some part of your page:

    <script type="text/javascript">
    if(self != top) { top.location = self.location; }
    </script>

    (This will break the iframe call and 'put' you page url)

    (That's the most simple one, has it's pros and cons)
    for a extended list visit this site:

    http://www.willmaster.com/library/we...RL-masking.php
    • [ 1 ] Thanks
    • [1] reply
  • For a "PHP solution" that can do the trick, try something like:
    Code:
    <?php
    if($_SERVER['PHP_SELF'] != "/index.php") {
    echo '<script language="javascript" type="text/javascript">
    <!--
    	window.onload = function() {
    		if (top.location != location) {
    			top.location.href = document.location.href ;
    		}
    	}
    //-->
    </script>';
    }
    ?>
    Still basically Javascript, but cloaked in PHP. It won't stop all embeds, e.g. where visitors have Javascript turned off, or the new "super iframes" that Google Images and others use. To stop those, you have to go the "X-FRAME-OPTIONS: SAMEORIGIN" via HTTP headers route, which isn't a "frame-buster" per se, but will block sites that embed yours (i.e. visitors won't see anything embedded).

Next Topics on Trending Feed