Hello everyone

I am not sure if this is the correct place to ask this question; but since it involves PHP I felt that I should try. I have 3 questions

  1. What is the best way to block a region/country from accessing a site?

  2. Is it possible to create a ‘fake IP address’ so that it fools a website into thinking the user is accessing the site from a different country?

  3. Where can I get the list of IP addresses from?

I have built a travellers members sites (a guide to travelling around the world); the problem is that I have fake travellers registering on the site and then targeting legitimate members with fake scams.

i am now spending a substantial amount of my time searching out these fake members and deleting them from the site. I have noticed that all the fake travellers come from a certain african country ( I will not mention the name but i suspect that everybody knows which country I am talking about).
Accordingly, rather than waste my valuable time on ‘search and delete’ operations, why not simply block the entire country or region from, where the scammer are accessing the site,

Question One

What is the best and most cost effective way to block a region or country.

I realise that it’s possible to use .htaccess to block regions/countries; but I have also read that this solution is very consuming on your systems and also slows your systems down. Is there a PHP/Mysql solution that will not be a drain on my systems and will also not slow down my site.
I was thinking of using the following function to block user from registering on the site.

It works by simply checking whether the IP address of a 'proposed new member' is a blocked IP address :

//first obtain the IP address of user 
$value  =    mysqli_real_escape_string ($dbc, $_SERVER['REMOTE_ADDR']);



//Next; check if it’s a banned or blocked IP address


	// If   a banned IP address is submitted 
	// the system will simply return an empty string-and since the system requires an IP //address for registration-  the user is simply prevented from registering.

function   banned_IPaddresses($value) {

  	$banned_IP = array('91.228.1.85' );

foreach ($banned_IP as $v) {
		if (stripos($value, $v) !== false) return '';
	}

}	

Question Two

I am using the code below to track the IP address of users to my site. The problem is that I am now engaged in a ‘cat and mouse game’ with this scam gang; they know that the ONLY WAY that I have been able to catch them thus far is by their IP addresses (i.e. they claim on their profile that they live in one country but the IP address clearly shows that they are actually accesses the site from another country).

I am therefore extremely concerned that they will soon find a way to fool my systems into thinking that they are indeed accessing the site from the stated country.

My question therefore is this; is it possible to do this or can I reply upon the code below to give me an accurate reading of where a user is accessing my system from.
If not, is there a better system/function for tracking IP addresses ?


$IP =    mysqli_real_escape_string ($dbc, $_SERVER['REMOTE_ADDR']);


				$SSID = htmlentities(SID);
				// If IP address exists
				// Get country (and City) via  api.hostip.info
			if (!empty($IP)) {
				$country=file_get_contents('http://api.hostip.info/get_html.php?ip='.$IP);

				// Reformat the data returned (Keep only country and country abbr.
                              list ($_country) = explode ("\n", $country);
                              $_country = str_replace("Country: ", "", $_country);

                            }


Question Three
Does anybody know where I can find the codes for IP addresses from; i.e the country and region codes ?

Thank you very much for your help everyone.

Warm regards

Andreea

    Hello again everyone
    Thank you to vivek151189 . Unfortunatelythe links only refer to blocking the IP at the Apache/Linux level.

    i want to avoid this as i heard that its a massive drain on the speed of the operatings systems.

    so, hopefully still watiing for a responce.

    regards

    Andreea

      Blocking at the web server level is appropriate: that's part of it's job.

      andreea115 wrote:

      i want to avoid this as i heard that its a massive drain on the speed of the operatings systems.

      That doesn't even make sense. The operating system and web server are still going to be involved anyway; you can't avoid using them by running a PHP interpreter and script as well.

        I have never heard of .htaccess consuming inordinate amounts of resources.

          I would suggest implemting the PEAR Net_GeoIP package. Use that to get the country of the IP address. Then you only have to know the country name and not the individual IP ranges you want to deny.

          You can spoof your IP address or use a proxy to get around IP blocks. The GeoIP module should be able to even do reverse proxies to get the true country of origin; however, I've never done this.

          @ - The .htaccess isn't the problem with Apache. It's that .htaccess can live in any directory which means Apache has to traverse your entire code tree to collect all of them. That's the expensive part. And if you have a lot of complex rules it can slow it down a miniscule amount; however, we're talking fractions of a second in today's computers.

            bpat1434;11005284 wrote:

            @ - The .htaccess isn't the problem with Apache. It's that .htaccess can live in any directory which means Apache has to traverse your entire code tree to collect all of them. That's the expensive part. And if you have a lot of complex rules it can slow it down a miniscule amount; however, we're talking fractions of a second in today's computers.

            I imagine in a situation like this the .htaccess file would be in the root of the project.

              3 months later
              KernelJay wrote:

              There is an issue with how Apache & PHP integrate which could render the htaccess restrictions useless. Automated tools exist for exploiting this weakness as outlined here

              Good point to raise, but I note that that issue is really about a flawed webserver configuration. The problem can show up even if you are using the main configuration file rather than .htaccess files.

                laserlight;11011187 wrote:

                Good point to raise, but I note that that issue is really about a flawed webserver configuration. The problem can show up even if you are using the main configuration file rather than .htaccess files.

                Agreed. The issue is in general with the use of '<LIMIT GET>' rather than specifically with the .htaccess file. Thanks for the feedback!

                  andreea115;11005228 wrote:

                  Question Three
                  Does anybody know where I can find the codes for IP addresses from; i.e the country and region codes ?

                  Afrinic? http://www.afrinic.net/

                    In general, I think this IANA page should be helpful: http://www.iana.org/numbers/

                    There are commercial products available which aid in blocking traffic based on Geolocation and IP reputation which would probably work much better than anything you can implement in an Apache configuration. If you do want to hardcode some firewall rules, here is a link to a Geo-IP tool I just found through Google: http://software77.net/geo-ip/

                    This site can provide useful information like the CIDR ranges for Afghanistan:

                    Report generated on Mon Aug 20 19:06:17 2012

                    by http://software77.net/geo-ip/

                    Report Type : CIDR format

                    Country : Afghanistan

                    ISO 3166 CC : ALPHA-2 AF; ALPHA-3 AFG

                    Registry : APNIC

                    Records found: 34

                    27.116.56.0/22
                    58.147.128.0/19
                    61.5.192.0/20
                    91.109.216.0/21
                    103.5.172.0/22
                    103.5.196.0/23
                    103.7.104.0/22
                    103.12.96.0/22
                    103.13.64.0/22
                    103.14.24.0/24
                    103.23.36.0/22
                    103.23.247.0/24
                    103.28.132.0/22
                    103.247.198.0/24
                    111.125.152.0/21
                    111.223.244.0/22
                    117.55.192.0/20
                    117.104.224.0/21

                      Write a Reply...