PHP / Javascript检查是否在特定的iframe中运行[重复]

This question already has an answer here:

Is there a way to check in either PHP or Javascript (preferrable PHP), if the current page is running in an iFrame on a specific page. So, I'd like something like this:

if(runningInIframeFromPage("http://www.myAwesomeWebsite.com")){
    //go on with script
}

Is this possible?

</div>

To know if the page is in an iFrame, you can use this:

if (window!=window.top) { /* iframe */ }

So it's just a matter of checking with window.top.location.hostname (just the domain, not entire URl. For entire URL is .href)

if (window!=window.top) {
    if(window.top.location.hostname = "www.myAwesomeWebsite.com" || window.top.location.hostname = "myAwesomeWebsite.com" ){
        /* code if domain is myAwesomeWebsite.com or www.myAwesomeWebsite.com  */
    }
}

Part of this question has been answered before:

if (parent==top) { // ...

With regard to the PHP part - no, this is not possible, however you could always use the JavaScript check to fire off an Ajax request to dynamically load in the content you want.