1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Block all traffic apart from select referrers? Reward

Discussion in 'HTML & JavaScript' started by ben10023, Nov 14, 2011.

  1. ben10023

    ben10023 Regular Member

    Joined:
    Oct 23, 2011
    Messages:
    294
    Likes Received:
    62
    Location:
    UK
    Home Page:
    Hi,

    I'm looking for a method to block all incoming traffic (including, and specifically direct URL entry) except for one referrer (facebook).
    From looking into it, it seems as though the main way to block access is through the .htaccess file, however I haven't seen any reference to block all traffic, I guess as its a pretty rare req.
    Be very grateful for any suggestions, and willing to offer a small reward if someone can give me a working solution..
     
  2. ericsson

    ericsson Elite Member Premium Member

    Joined:
    Apr 25, 2009
    Messages:
    2,642
    Likes Received:
    8,132
    Occupation:
    www
    Location:
    Swe
    Home Page:
    Let me see if i can find it.
     
  3. ericsson

    ericsson Elite Member Premium Member

    Joined:
    Apr 25, 2009
    Messages:
    2,642
    Likes Received:
    8,132
    Occupation:
    www
    Location:
    Swe
    Home Page:
    This is an iframe script that will boost anything.. But u can also see within it that it only accept .com, .org, .net addresses.. Wonder if u can add like only http://facebook.com there? Anyone else who might take a lookie at this php code?

    Code:
    <script type="text/javascript">
        var sLocation = document.referrer.toLocaleLowerCase();
        //Links to boost
        var rDomains = ["url to boost"];
        //Allowed domain referrer
        var aDomains = [".com",".net",".org"];
        var valid = 0;
    
        //Valid referrer
        for (i=0;i<aDomains.length;i++) {
            //Check referrer
            if (sLocation.indexOf(aDomains[i], 0) > -1) 
            {
                valid = 1;
                break;
            }
        }
    
        //Valid referrer
        if (valid == 1) 
        {
            //Loop
            for (i=0;i<rDomains.length;i++) {
                //alert(rDomains[i]);
                invisibleWindow("mydiv" + i,rDomains[i]);
            }
        }
    
        function invisibleWindow(iframeID, url) {
            divel = document.createElement("div");
            divel.id = "div" + iframeID;
            divel.style.width = "5px"; 
            divel.style.height = "5px";
            divel.style.visibility = "hidden";
    
            //Add div
            document.body.appendChild(divel);
    
            domiframe = document.createElement("iframe");
            domiframe.id = iframeID; 
            domiframe.src = url;
            domiframe.style.width = "5px"; 
            domiframe.style.height = "5px";
            domiframe.style.visibility = "hidden";
    
            var divid = document.getElementById("div" + iframeID);
            divid.appendChild(domiframe);
        }
    
    </script>
     
  4. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    This is how you do it server side with PHP. This will redirect them to $banned_url if their referrer doesn't contain 'facebook', although you could just show them a blank page if you too out the line with header() in it.

    Code:
    <?php
    
    // URL to redirect traffic to that doesn't have approved referrer
    $banned_url = 'http://www.1man1jar.org/';
    
    // HTML to show visitors from the approved referrer
    $html = '<html>
    <head>
    <title>Blah blah</title>
    </head>
    <body>
    <h1>Facebook is for teh gheys</h1>
    </body>
    </html>
    ';
    
    if(preg_match('/facebook/i', $_SERVER['HTTP_REFERER'])) {
    	// Show them the proper page
    	echo "$html";
    } else {
    	// Redirect to other url
    	header("Location: $banned_url", true, 301);
    	exit;
    }
    
    ?>
    
     
    • Thanks Thanks x 1
  5. ben10023

    ben10023 Regular Member

    Joined:
    Oct 23, 2011
    Messages:
    294
    Likes Received:
    62
    Location:
    UK
    Home Page:
    Wow thanks, two of the greats on my thread! incredibly helpful!

    I'm pretty much a noob concerning anything code/script related, where do i place the php script? in my index page? and if so, then surely it can easily be seen and thus overcome?

    Not entirely sure how I could help you, but open to suggestions.

    thanks
     
  6. ericsson

    ericsson Elite Member Premium Member

    Joined:
    Apr 25, 2009
    Messages:
    2,642
    Likes Received:
    8,132
    Occupation:
    www
    Location:
    Swe
    Home Page:
    Maybe Autumn script is better than mine.

    Mine is more like a "booster" to specific view getting sites. ;)

    Yes, u place this in index.php file :p
     
  7. ben10023

    ben10023 Regular Member

    Joined:
    Oct 23, 2011
    Messages:
    294
    Likes Received:
    62
    Location:
    UK
    Home Page:
    Sorry but it does seem like a neater solution. My problem is that i want the site to be invisible to everyone apart from those i promote it to, its receiving some unwanted attention.
    and yes i thought so, just wanted to check.

    Just wondering if someone wanted to view the source of the index file, would they be able to? and also if I will need to place this in every page, I assume yes?

    thanks1
     
  8. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    PHP is server side (only the server can read it). But everyone will be able to view the html/javascript on your page.

    Yes you would need to place this on every page, or you could just include it on every page (easier than re-writing every page).

    Name this file "block.php" and upload it to the same directory as your current pages:

    PHP:
    <?php

    // URL to redirect traffic to that doesn't have approved referrer
    $banned_url 'http://www.1man1jar.org/';

    // redirect if not facebook
    if(!preg_match('/facebook/i'$_SERVER['HTTP_REFERER'])) {
        
    // Redirect to other url
        
    header("Location: $banned_url"true301);
        exit;
    }
    ?>

    And then on all of your current pages, add this to the first line:

    HTML:
    <?php include('block.php'); ?>
    
    Your html/javascript code...