Allow a page to only load in an iframe and prevent

2019-08-14 21:29发布

问题:

How can I allow my PHP file to only load in an iframe?

For example:

Prevent direct access:

example.com/Loader.php

Allow iframe access:

<iframe name="TEST" src="Example.com/Loader.php"></iframe>

回答1:

You can use JavaScript for that

if(window==window.top) {
    // not in an iframe
}