JimHalpert
Supreme Member
- Jan 16, 2016
- 1,345
- 292
Hi everyone,
I happened to be reading threads of people making geo-rotating scripts using Geolite as per this post (https://www.blackhatworld.com/seo/need-someone-to-code-for-me-php-geo-targetting.41585/#post-410382).
It seems like GeoLite has been changed to GeoIP2 and the installation procedure seems alot more complicated (https://packagist.org/packages/geoip2/geoip2). Could someone provide some guidance on how to install GeoIP2. For example, on the installation page it is stated:
More importantly, would the script in the post above still work? I have reproduced it below.
Many thanks.
I happened to be reading threads of people making geo-rotating scripts using Geolite as per this post (https://www.blackhatworld.com/seo/need-someone-to-code-for-me-php-geo-targetting.41585/#post-410382).
It seems like GeoLite has been changed to GeoIP2 and the installation procedure seems alot more complicated (https://packagist.org/packages/geoip2/geoip2). Could someone provide some guidance on how to install GeoIP2. For example, on the installation page it is stated:
To download Composer, run in the root directory of your project:
curl -sS https://getcomposer.org/installer | php
You should now have the file composer.phar in your project directory.
For example, how does one run it in your project root directory?More importantly, would the script in the post above still work? I have reproduced it below.
PHP:
<?php
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, "$ip");
// Country name is not used so commented
// Get Country Name based on source IP
//$country = geoip_country_name_by_addr($gi, "$ip");
geoip_close($gi);
switch($country_code)
{
case "US": header("Location: http://Your_American_page"); break;
case "CA": header("Location: http://Your_Canadian_Page"); break;
case "UK": header("Location: http://Your_U.K._Page"); break;
case "AU": header("Location: http://Your_Australian_Page"); break;
default: header("Location: http://Where_the_rest_of_the_visitors_go");
}
?>
Many thanks.
Last edited: