I have a page thisfile.htm, which is included in thisfile.php
I used to load thisfile.htm into an iframe on thisfile.php but because of iPad scrolling trouble, I recently converted everything to scrolling divs and php includes.
I need to prevent the htm file from being loaded independently of the php parent. When I used iframes, I had no problem doing this with some javascript. But I can't get it to work with my php include - I get a loop.
This is in child:
<script type="text/javascript">
if(top.location.href==self.location.href) {
location.replace("thisfile.php");
}
</script>
This is in parent:
<div class="bigdiv"><?php include "thisfile.htm" ?></div>
Thank you in advance.
If you are using include
in php, the easiest way to protect the file you are including, is to place it outside of the web-root. That way php can get to it, but a browser can´t so it can never be loaded separately. You don´t need any javascript in the child if you do it like this.
If thisfile.htm is to be included in a div in thisfile.php, just include it in php, using include
. You don't have to call thisfile.htm from the outside at all. In fact, you could place it outside your doc root, in which case you cannot reach it from outside at all. It will only be included in thisfile.php.