Check to to see if I'm being framed ?????

Discussion in 'Programming' started by sSoft, May 2, 2006.

  1. #1
    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.
     
    sSoft, May 2, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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):
     
    mad4, May 2, 2006 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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...
     
    TwistMyArm, May 2, 2006 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can't do it in Php, and the code you've posted is Javascript, not Java. :)
     
    exam, May 2, 2006 IP
  5. dcole07

    dcole07 Peon

    Messages:
    135
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    dcole07, May 3, 2006 IP
  6. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #6

    This will not work.

    THe page still exists on your server so the URL will be that of the page not the parent frame
     
    Danny, May 3, 2006 IP
  7. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you redirect with php the only thing you redirect is the inner frame, the outer frameset will remain at the same location.
     
    mad4, May 3, 2006 IP