X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Determine the customer country from the IP address (https://forum.x-cart.com/showthread.php?t=38032)

virtual@croatia 03-04-2008 07:48 AM

Determine the customer country from the IP address
 
8 Attachment(s)
Important!: This feature is implemented in all new xcart versions, so my work on this is discontinued.

This modul recognizes the customer country and chooses the right language for him. In the combination with the Multi_Currency module it sets the right currency as well.

Country page in admin mode is slightly modified and you can choose a proper language for the country (for example, country San Marino - language Italian).

As the data file is bigger than 512 kb I had to split it in separate files. Please, unpack everything, open "ip_range_1.sql" from "ip-range_1.zip", copy the text and paste it at the end of "sql/x-ip_range.sql" file from "x-iprange-4.1.7.zip file". Do it again with "ip-range_2.sql".

All ip range data is completely updated and 2 new countries will be added:
1. Serbia
2. Montenegro

All changes are visible in the admin area at the "countries" page.

http://www.smee.hr/skin1/images/xcart%20forum/ip_range_admin.jpg

and on the statistic page:

http://www.smee.hr/skin1/images/xcart%20forum/ip_range_statistic.jpg



For all problems send a post here or email to me.

Important!
If you want to use it with Multi_Currency module, you have to install the IP_Range module first!
If you miss to do that you have to change line 67 in include/data_cache.php from


PHP Code:

$all_active_modules func_query_column("SELECT module_name FROM $sql_tbl[modules] USE INDEX (active) WHERE active='Y'"); 

to
PHP Code:

$all_active_modules func_query_column("SELECT module_name FROM $sql_tbl[modules] USE INDEX (active) WHERE active='Y' ORDER BY module_name"); 


New version uploaded 08/04/2008 - fixed error "FAILED] Table 'mydatabasename.tmp' doesn't exist" and upgraded to 4.1.9 version. Tested with freshly installed 4.1.9 version.
New version uploaded 10/04/2008 - fixed error with no displaying default currency in the country management
New version uploaded 13/04/2008 - robots are excluded from the list and included in a separate table
New version uploaded 16/04/2008 - fixed error "Table 'xcart_stats_robots' doesn't exist"

pauldodman 03-04-2008 08:00 AM

Re: Determine the customer country from the IP address
 
What happens if you are in a country but don't speak that language?

virtual@croatia 03-04-2008 09:28 AM

Re: Determine the customer country from the IP address
 
Quote:

Originally Posted by pauldodman
What happens if you are in a country but don't speak that language?


You mean, if the customer doesn't speak the langauge which is usually spoken in the country where he's browsing from?

Nothing, he will have to choose another language from the language menu.

junaid 03-05-2008 01:32 AM

Re: Determine the customer country from the IP address
 
would it be possible if we can redirect customer with certain ip to different page on site using this mod.
regards
Junaid

virtual@croatia 03-05-2008 02:02 AM

Re: Determine the customer country from the IP address
 
Quote:

Originally Posted by junaid
would it be possible if we can redirect customer with certain ip to different page on site using this mod.
regards
Junaid


It is not included right now, but it is very easy to add this feature. At the beginning of the page modules/IP_Range.php are two rows which recognizes the user country:

PHP Code:

$ip_addr $_SERVER['REMOTE_ADDR'];
$ip_country func_query_first_cell ("SELECT iso2 FROM $sql_tbl[ip_ranges] WHERE $sql_tbl[ip_ranges].start <= INET_ATON('$ip_addr') AND $sql_tbl[ip_ranges].end >= INET_ATON('$ip_addr') LIMIT 1"); 



After this line you can redirect the user wherever you want depending the $ip_country variable.

POSDepot 04-07-2008 07:53 AM

Re: Determine the customer country from the IP address
 
getting this error during installation

FAILED] Table 'mydatabasename.tmp' doesn't exist

Thanks
Randy

exsecror 04-07-2008 09:10 AM

Re: Determine the customer country from the IP address
 
You'd actually be better off using the GeoIP service for that, however I should note that those types of lists are not generally accurate due to how often IP blocks are sold and resold and information is not updated. In either case the GeoIP service from Maxmind is better (there's a PHP extension for it).

An example is GeoIP says I live in Los Angeles California when in fact I do not but that's because the IP's delegations belong to MegaPath which is in LA.

virtual@croatia 04-07-2008 10:56 AM

Re: Determine the customer country from the IP address
 
Quote:

Originally Posted by POSDepot
getting this error during installation

FAILED] Table 'mydatabasename.tmp' doesn't exist

Thanks
Randy


I will check it tomorrow morning, you can expect the patch tomorrow.

Regards,
virtual@croatia

virtual@croatia 04-08-2008 05:17 AM

Re: Determine the customer country from the IP address
 
Quote:

Originally Posted by exsecror
You'd actually be better off using the GeoIP service for that, however I should note that those types of lists are not generally accurate due to how often IP blocks are sold and resold and information is not updated. In either case the GeoIP service from Maxmind is better (there's a PHP extension for it).


If you want to use this modul just for the statistic, than it's better to use some external tool, for example GeoIP. But, the difference between this modul and external tool is that you can use this data in php and generate pages depending of the user country.
For example, if you have multilanguage site, this modul will choose the right language depending of the user country and in combination with multicurrency modul, which you can find on the same forum, it will choose the right currency for the user.
You can see how it works on my web site www.smee.com. If you are coming on the web site from US, the language will be English and the currency will be US$. If you are coming from Germany, the language will be German and the currency EUR.

Regards,
virtual@croatia

virtual@croatia 04-08-2008 06:38 AM

Re: Determine the customer country from the IP address
 
Quote:

Originally Posted by POSDepot
getting this error during installation

FAILED] Table 'mydatabasename.tmp' doesn't exist

Thanks
Randy


Fixed! Please download the last version from the top post of this thread.

Regards,
virtual@croatia


All times are GMT -8. The time now is 05:12 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.