key .. my problem is a little bigger .. so .. How can I check through PHP to to see if I'm being framed by another site and if i am what site is framing me. Example: a page from my site is loaded in a frame on another site. When this happens i want my page to check if she's being framed and by who . I've started to do this in Java .. if (top.location != window.location) { alert("I am framed"); } Code (markup): but i need something more dinamic and with access to db that i`m using .. so .. is there any way to check from php what i've just asked. Hope you understand my english .. and i really do hope somebody can help me. Thank you in advance.
You can't break out of a frame with php, htaccess should do it though...... Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^domain.com RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] Code (markup):
Naturally, PHP can't help you by itself as it's server side. What you're asking for is client side code. If you wanted to, you could play around with an asynchronous request back to the server through JavaScript if the locations are found not to match (not true AJAX, but that kind of thing). However... if your page is from a different server to the one framing it, then it is a bug in the browser if you can access the location of the 'parent' window. That is to say even if it works for some browsers at the moment, don't expect it to work in the future. One thing that I'd look into: what value (if any) is sent as the referrer when a page is loaded in a frame? Alternatively, if you find that the locations don't match, just change the document source location to point to a 'naughty, naughty, naughty!' page...
You can do it will php!!! on the page you thing is being framed, use php to get the current URL. Then you can write the URL to a file. You can put an if statement to make sure it's not your URL and if it's not your URL you can have it redirect to your page.
This will not work. THe page still exists on your server so the URL will be that of the page not the parent frame
If you redirect with php the only thing you redirect is the inner frame, the outer frameset will remain at the same location.