How to block IP countries with php?

by bbcrew
5 replies
I try to do following Blocking Website Access by Country with PHP | Azulia Designs but when I check my site with my country ip it still access and error occur because it not found .php in ip_files folder.

So, I want to know other methods that easy and works fine.

Thank you very much.
#block #countries #php
  • Profile picture of the author h4x0r
    Well try to find an API, you can find a public one easily that can tell you what country is of IP and then you can write php code to let allow to redirect it somewhere. Google for public api's to get country by IP
    {{ DiscussionBoard.errors[8284021].message }}
  • Profile picture of the author Beatinest
    I do it via htaccess instead of php. If you can't get the php to work it's an option for you.
    Signature
    {{ DiscussionBoard.errors[8296865].message }}
  • Profile picture of the author skillboyz
    You can do it usign htaccess or you should have a IP to country database and then you can restrict using php script
    {{ DiscussionBoard.errors[8297490].message }}
  • Profile picture of the author 1stranked
    Note that if anyone is using proxy it can avoid IP filtering.
    {{ DiscussionBoard.errors[8298305].message }}
  • Profile picture of the author sktthemes
    You can use xforwarded for header info:

    if($_SERVER["HTTP_X_FORWARDED_FOR"] != ""){ $IP = $_SERVER["HTTP_X_FORWARDED_FOR"]; $proxy = $_SERVER["REMOTE_ADDR"]; $host = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]); }else{ $IP = $_SERVER["REMOTE_ADDR"]; $proxy = "No proxy detected"; $host = @gethostbyaddr($_SERVER["REMOTE_ADDR"]); }
    {{ DiscussionBoard.errors[8299001].message }}

Trending Topics