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.

How to block visitor if hostname contain a custom word

Discussion in 'PHP' started by moath11, Jul 29, 2014.

  1. #1
    hello guys,

    i'm trying to create a simple script that block an user if the hostname contain an custom word

    for example if the user hostname contain "proxy" or "vpn"
    then the script should block that user and print white page or 404


    any help ?
     
    Solved! View solution.
    moath11, Jul 29, 2014 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    You can use the HTTP_HOST server variables against the words using stripos method.
     
    ThePHPMaster, Jul 29, 2014 IP
  3. Helge Sverre

    Helge Sverre Prominent Member Affiliate Manager

    Messages:
    840
    Likes Received:
    99
    Best Answers:
    2
    Trophy Points:
    305
    Digital Goods:
    2
    #3
    If i'm not totally off this should give you the functionality that you want.

    <?php
    
    if (substr_count($_SERVER["REMOTE_HOST"], "vpn") > 0) {
        die("Access denied, do not use a proxy!");
    }
    
    ?>
    PHP:
    Live example: http://test.helgesverre.com/proxytest.php

    Note: Your web server must be configured to create this variable.
    For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist.
     
    Helge Sverre, Jul 31, 2014 IP
  4. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    thank you, how i can block multi words ?

    vpn, proxy, word3 ?
     
    moath11, Jul 31, 2014 IP
  5. #5
    <?php
    $blocked_words = array(
         "vpn",
         "proxy",
         "word3"
    );
    
    
    foreach($blocked_words as $word) {
        if (substr_count($_SERVER["REMOTE_HOST"], $word) > 0) {
            die("Access denied, do not use a proxy!");
        }  
    }
    
    ?>
    PHP:
    There you go :)
     
    Helge Sverre, Jul 31, 2014 IP
    sarahk likes this.
  6. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    thank you
     
    moath11, Jul 31, 2014 IP
  7. Helge Sverre

    Helge Sverre Prominent Member Affiliate Manager

    Messages:
    840
    Likes Received:
    99
    Best Answers:
    2
    Trophy Points:
    305
    Digital Goods:
    2
    #7
    You're welcome.
     
    Helge Sverre, Jul 31, 2014 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    And, if you're smart, you'll change all those double quotes to single quotes, as they're not being parsed - with double quotes, PHP looks for variables inside the quotes, while it doesn't do that with single quotes. Not that important in this case, but a thing to remember when the amount of code-lines goes up into thousands, and you're looking for ways to improve speed.
     
    PoPSiCLe, Aug 1, 2014 IP
    sarahk likes this.
  9. Helge Sverre

    Helge Sverre Prominent Member Affiliate Manager

    Messages:
    840
    Likes Received:
    99
    Best Answers:
    2
    Trophy Points:
    305
    Digital Goods:
    2
    #9
    Ahh, yes!
    Although in this case it doesn't matter that much.
     
    Helge Sverre, Aug 3, 2014 IP
  10. chrisnagios

    chrisnagios Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #10
    there are much smarter ways to block proxies,
    maxmind DB geolite free, with cool accuracy,
    does return "Anonymous Proxy" for proxy users,
    instead of country, so this shall be much better
     
    chrisnagios, Aug 11, 2014 IP