Sunday 20 April 2008 11:49:41 pm
hello, i have done this. i have downloaded ip2country records from here http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip I have made one table tbl_ip2country and import all records. Columns of this table is "id,ip_from,ip_to,country_code2,country_code3,country_name" now in access.php file, put this line at top.
define( 'DO_AS_PER_LOCALE', 1 );
include_once( 'lib/ezdb/classes/ezdb.php' );
now in function accessType, at line approximately 262, between if and else if
else if(DO_AS_PER_LOCALE == true && $_SERVER['REMOTE_ADDR'] != "127.0.0.1")
{
// to run this, we have to change db name from settings/site.ini "nextgen" to the current database name
// and we need ip2country table in that database.
$remoteIp = $_SERVER['REMOTE_ADDR'];
//$remoteIp = "121.247.167.243"; for testing => india
$q = "select * from tbl_ip2country
where
((SUBSTRING_INDEX( '$remoteIp' , '.', 1 ) * (256*256*256)) +
(SUBSTRING_INDEX(SUBSTRING_INDEX( '$remoteIp' , '.', 2 ),'.',-1) * (256*256)) +
(SUBSTRING_INDEX(SUBSTRING_INDEX( '$remoteIp' , '.', -2 ),'.',1) * 256 ) +
SUBSTRING_INDEX( '$remoteIp' , '.', -1 ))
between ip_from and ip_to
";//and lower(country_code2) = 'fr'
$db = eZDB::instance();
$result = $db->arrayQuery($q);
if(count($result) > 0 && strtolower($result[0]['country_code2']) == "fr")
{
// language is french
$access['name'] = "fre";
}
else
{
$access['name'] = "eng";
// language is english
}
$access['type'] = EZ_ACCESS_TYPE_URI;
}
and one more thing to do in settings/site.ini file we have to change this because site.ini file loads after the upper code executes.
User=dbusername
Password=dbpassword
Database=dbname
With Best Regards,
Dhaval Patel
Team Leader - iNETProcess(I) Pvt. LTD.
[email protected]
Ph No: +91 79 65 12 35 00
http://www.inetprocess.co.in
|