Thread: Blocking A User

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    202
    Rep Power
    4

    Blocking A User


    Hi,

    I need to block various countries from accessing my site (for reasons i won't go into right now... other than being compliant and meeting regulations with my payment provider... please don't make this the topic).

    I am not sure if it is best / easiest to block all of the my site or just certain page from these countries... anyway, my question is... what is the best way to block specfic countries...

    I have the GEO MaxMind database feeding into my site, however would querying each users IP address against my GEO database pull a lot of resources out of my site... can anyone suggest a better way to achieve this (if there is one...), thanks in advance...
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    That depends on how fast the IP query is. You shouldn't have a problem doing this.

    I worked at a company which not only blocked entire countries, but had a "karma" system which assigned a point value to every country, browser type, OS, etc. A windows user from Taiwan could get in, but a linux user could not.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    202
    Rep Power
    4
    Ok cool, thanks... i just think that making these queries each time could be demanding on the database...
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    How many queries are you doing to draw the page? Devshed does dozens on each page load.

    Total query time may be an issue, but if that's the case you have to optimize your system.

    There is no way to figure out what country someone is from without looking in a country database.

    You could cache this information, or use the session (though sessions are easily subverted)
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    202
    Rep Power
    4
    Thanks... what would you think of this comment:

    Query GEO database ONCE and build an array of blocked IP's. Then compare visitors IP to this array using in_array() and act accordingly.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    I say that depends on what scenarios they're talking about, whether they're caching the array, etc. It sounds wrong for a single inbound request, but it's obviously from a longer discussion.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Query GEO database ONCE and build an array of blocked IP's. Then compare visitors IP to this array using in_array() and act accordingly.
    The array would almost certainly be too large for this to be practical.

    You only need to run the query once per session. The user isn't going to move from one country to another country while simultaneously browsing your site. Just cache the result allow / not allowed in the session.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    If you're doing this for abuse reasons, using the session may not work since they can just delete their cookie and try again. Normally what I did was just not allow them to log in. They could keep hitting the login button all they wanted, but they'd get a "bad password" screen every time if their IP was in a bad country.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    202
    Rep Power
    4
    Is there any site that will allow you to access a site from another country so that you can test your site against blocked countries?
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Opera mini routes all traffic through Norway. Or you could use a free proxy.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo