Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Determine the customer country from the IP address

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 03-04-2008, 07:48 AM
 
virtual@croatia virtual@croatia is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 92
 

Default Determine the customer country from the IP address

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"
Attached Files
File Type: zip ip-range_1.zip (397.1 KB, 112 views)
File Type: zip ip-range_2.zip (329.6 KB, 108 views)
File Type: zip x-iprange-4.1.9.zip (14.1 KB, 114 views)
__________________
Check what you can do with x-cart 4.1.9:
www.smee.com

Modules I made:
IP_Ranges
Multy_Currency
Order_Dates

Modules I use:
Fancycategory
Magnifier
Survey
AOM
Reply With Quote
  #2  
Old 03-04-2008, 08:00 AM
  pauldodman's Avatar 
pauldodman pauldodman is offline
 

X-Guru
  
Join Date: Jul 2003
Location: Spain / UK
Posts: 3,023
 

Default Re: Determine the customer country from the IP address

What happens if you are in a country but don't speak that language?
__________________
Paul Dodman
e-business & m-commerce consultant
w: www.luminointernet.com
e: xcart@luminointernet.com

Professional X-Cart help, advice, support and services, specialists in Mobile X-Cart.
Reply With Quote
  #3  
Old 03-04-2008, 09:28 AM
 
virtual@croatia virtual@croatia is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 92
 

Default 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.
__________________
Check what you can do with x-cart 4.1.9:
www.smee.com

Modules I made:
IP_Ranges
Multy_Currency
Order_Dates

Modules I use:
Fancycategory
Magnifier
Survey
AOM
Reply With Quote
  #4  
Old 03-05-2008, 01:32 AM
 
junaid junaid is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 96
 

Default 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
__________________
xcart 4.18 on linux
Reply With Quote
  #5  
Old 03-05-2008, 02:02 AM
 
virtual@croatia virtual@croatia is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 92
 

Default 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.
__________________
Check what you can do with x-cart 4.1.9:
www.smee.com

Modules I made:
IP_Ranges
Multy_Currency
Order_Dates

Modules I use:
Fancycategory
Magnifier
Survey
AOM
Reply With Quote
  #6  
Old 04-07-2008, 07:53 AM
 
POSDepot POSDepot is offline
 

Advanced Member
  
Join Date: Sep 2002
Posts: 52
 

Default Re: Determine the customer country from the IP address

getting this error during installation

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

Thanks
Randy
__________________
X-Cart Gold
4.1.9
Reply With Quote
  #7  
Old 04-07-2008, 09:10 AM
 
exsecror exsecror is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,284
 

Default 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.
Reply With Quote
  #8  
Old 04-07-2008, 10:56 AM
 
virtual@croatia virtual@croatia is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 92
 

Default 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
__________________
Check what you can do with x-cart 4.1.9:
www.smee.com

Modules I made:
IP_Ranges
Multy_Currency
Order_Dates

Modules I use:
Fancycategory
Magnifier
Survey
AOM
Reply With Quote
  #9  
Old 04-08-2008, 05:17 AM
 
virtual@croatia virtual@croatia is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 92
 

Default 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
__________________
Check what you can do with x-cart 4.1.9:
www.smee.com

Modules I made:
IP_Ranges
Multy_Currency
Order_Dates

Modules I use:
Fancycategory
Magnifier
Survey
AOM
Reply With Quote

The following user thanks virtual@croatia for this useful post:
manishp (03-12-2010)
  #10  
Old 04-08-2008, 06:38 AM
 
virtual@croatia virtual@croatia is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 92
 

Default 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
__________________
Check what you can do with x-cart 4.1.9:
www.smee.com

Modules I made:
IP_Ranges
Multy_Currency
Order_Dates

Modules I use:
Fancycategory
Magnifier
Survey
AOM
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:01 AM.

   

 
X-Cart forums © 2001-2020