1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is there a script or codes that prevent people from iframing your site?

Discussion in 'PHP' started by proxywhereabouts, Aug 29, 2009.

  1. #1
    Like said in the title, is there something like that?
    Reason asking was because sometime you get tired of other people iframing your site especially downloads site.

    Can anyone point me where I can find such code?

    Many thanks.
     
    proxywhereabouts, Aug 29, 2009 IP
  2. TheDataPlanet.com

    TheDataPlanet.com Well-Known Member

    Messages:
    503
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Use this:

    <script language="JavaScript">
    <!--
    	if (self.location.href != top.location.href) {
    		top.location.href = self.location.href;
    	}
    // -->
    </script>
    Code (markup):
    BTW: I think this should belong to the JavaScript forum. :) But if you need this in PHP, I believe checking $_SERVER['HTTP_REFERER'] is the way.
     
    TheDataPlanet.com, Aug 29, 2009 IP
  3. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #3
    Thanks.
    But can you share a code where when a page is being call by an iframe, it will show a custom page asking user to go to a link for that real page?BUT if the page is called by authentic user then it loads fine.

    Anyway to do this?
     
    proxywhereabouts, Aug 30, 2009 IP
  4. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    nice code dude..
     
    mdrobiul, Aug 30, 2009 IP
  5. vomers

    vomers Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Here is some code using php that will work


    <?php
    $checkSite = $_SERVER['HTTP_REFERER'];
    $sitename="www.yoursite.com";

    ?>
    <html>
    <body>
    <?php
    if (($checkSite == "")||($checkSite ==$sitename))
    {
    ?>
    Welcome to my site
    your page code codes here!!

    <?php
    }
    else
    {
    ?>

    Please visit my site at www.yoursite.com

    <?php
    }
    ?>
    </body>
    </html>
     
    vomers, Aug 31, 2009 IP
    proxywhereabouts likes this.
  6. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #6
    This is what I meant by people freaking iframing my site.
    http://freerapid.org/linkgenerator/2

    They iframed my site right from their site!

    I just want to have a code so that when people try to load my site in a frame, a message will show saying redirecting to the site and then it will redirect people straight to mine.

    Is it possible?
     
    proxywhereabouts, Sep 6, 2009 IP
  7. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    what's wrong with the examples just given above?
     
    szalinski, Sep 6, 2009 IP
    proxywhereabouts likes this.
  8. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #8
    Just noticed the code..sorry, I missed that one.
    Implemented and it works. Now, I going to implement on all my sites.

    Thanks both of you.:)
     
    proxywhereabouts, Sep 6, 2009 IP
  9. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #9
    Okay, this code works fine except that it detects my site using iframe too.
    Try go to "server files", tick one file and choose any "action" from the drop down menu. You'll see the message.
    Anyway to whitelist my own url?
     
    proxywhereabouts, Sep 7, 2009 IP
  10. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Try:

    
    	if (self.location.href != top.location.href && !top.location.hostname.match(/domain\.com/) {
    		top.location.href = self.location.href;
    	}
    Code (markup):
    If it doesn't work, it gives you an idea which you should expand upon..
     
    premiumscripts, Sep 7, 2009 IP
  11. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #11
    this problem can be solved with javascript, so i suggest to ask a mod to move this topic.
     
    hip_hop_x, Sep 7, 2009 IP
  12. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #12

    Thanks for the code but how to implement it?
    Should it be combined with vomer's code above?
     
    proxywhereabouts, Sep 7, 2009 IP
  13. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #13
    It's pure javascript, it doesn't need to be combined with anything. Ofcourse you'll have to edit it to change domain\.com to your domain.. (without www, index.html etc) and \ before .
     
    premiumscripts, Sep 7, 2009 IP
    proxywhereabouts likes this.
  14. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #14
    So, I can use it like this?

    
    <script type="text/javascript">if (self.location.href != top.location.href && !top.location.hostname.match(/rsmaker\.com/) { top.location.href = self.location.href;	}</script>
    
    PHP:

    **Updated: script not working. Link clicked from my own site still showing the iframe message.
     
    Last edited: Sep 7, 2009
    proxywhereabouts, Sep 7, 2009 IP
  15. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Since you PM'd me I'll show it to you.. I usually don't do this, please get a web development book and learn on your own, it will only help you with your online business..

    Your page you're trying to protect should be like this: (assuming rsmaker.com is your site)

    
    <html>
    <head>
    <script type="text/javascript">
    if (self.location.href != top.location.href && !top.location.hostname.match(/rsmaker\.com/)) { 
    	top.location.href = self.location.href;    
    }
    </script>
    </head>
    <body>
    .. site content ..
    </body>
    </html>
    HTML:
     
    premiumscripts, Sep 7, 2009 IP
  16. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #16
    [UPDATE]
    Code not working.
    1- Try go to www.rsmaker.com and once the page load, click on the logo. It supposed to go to the site again, like refresh but instead it shows the iframe message.
    2- Hmm...seems like any links on other sites pointing to my site was shown the message. Like the link I asked you to click above, it will show the same message. Going to remove the code for now until someone can tell me what did I do wrong.

    Thanks for those who helped, rep +.
    =========


    Appreciate your help. Basically what I pmed you just now was correct. :)
    I've got myself some reference ebook from sitepoint. Still getting myself used to it though as I barely finished php.

    Thanks again.

     
    Last edited: Sep 7, 2009
    proxywhereabouts, Sep 7, 2009 IP