Check if website is being iframed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
J0kerz
Forum Commoner
Posts: 37
Joined: Fri May 29, 2009 2:51 pm

Check if website is being iframed

Post by J0kerz »

hey there,

I know that in Javascript you can use window.top.location to check if your website is being iframed but I was wondering if there is anyway to do that in PHP?

I would like to retrieve the url of the website that is iframing me and do something.

Thanks!
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Check if website is being iframed

Post by Jade »

I don't know of any way to do it in PHP, sorry. Here's the Javascript.

[syntax]
if (top.location != location)
top.location.href = document.location.href;
[/syntax]
User avatar
J0kerz
Forum Commoner
Posts: 37
Joined: Fri May 29, 2009 2:51 pm

Re: Check if website is being iframed

Post by J0kerz »

Any way to do this in PHP?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Check if website is being iframed

Post by Jade »

PHP doesn't have a way to access nested window/iframe information, that's something you have to use Javascript for but you could always pass the information from Javascript back to PHP or run the Javascript by building it in PHP code. There's also Ajax.
Post Reply