geo4zen add-on

Views: 2,805

Results 1 to 14 of 14
10 Aug 2008, 10:39 PM
#1
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

geo4zen add-on

This adds a simple way to detect the country of your customer.

By default, the module sets a session variable you can use in your own programming.

for example:

if($_SESSION['customers_geo_iso'] == "CA") {some nice PHP code here...;}

It also sets $_SESSION['customers_geo_country'] with the text name of the country.

To make it a small bit useful out of the box, it includes a mechanism to either deny or allow access to the site on a country by country basis, and to specify an action for blocked countries. The default is to send a header re-direct to google, but you can be creative here and customize this action.

The default here is to deny access to IP's originating in the countries listed at the beginning if the ipcheck.php file. Edit these (line 4) as you wish.

To change the default action to Allow Only, edit line 50 of ipcheck .php and add the negation char to the in_array statement.

ie:
if (!in_array($iso2, $ban_array)){
// what to do with banned countries. Default = send them to google...
header('Location: http://www.google.com/'%29;
exit;
}

This will now allow access only to those countries defined at the top of the script.

Some other creative uses...

Here is where you must be creative. One example is if you own stores in different geographical areas, you can route customers to the proper store. For instance, you can easily route European customers to your .co.uk shop, and North American customers to your .com shop.

Another idea may be to set the store mode (normal vs showcase) based on customers location.

This is not 100% fool-proof as you can proxy around it if you are determined, but it has proven quite handy in some sites I do.

If you have any questions or find bad bugs, please post them to this thread.
Maybe post your nice code built using this.

There are some more details in the packages readme file.

Please be careful and test well before using this in a live shop.

Kiddo

4 Feb 2009, 3:47 AM
#2
dimmyr avatar

dimmyr

New Zenner

Join Date:
Jun 2008
Posts:
54
Plugin Contributions:
0

Re: geo4zen add-on

Hey, Kiddo. What lovely code! It would have been beautiful if it worked for me, but it somehow doesn't. All I am looking for is to redirect users from a specific country to a different site. To test it, I added US to the list of the "banned" countries, but it does not redirect me. I followed all your instructions, and currently the CSV is in the root.

My server is a WIMP - Windows IIS, MySQL, PHP. Does that matter?

Here is the edited portion of my ipcheck.php:

<?php
// Add the two letter iso country codes you want to ban to the line below.
// NG=Nigeria KR=Korea TH=Thailand CN=China...
$ban_array = array("US");
4 Feb 2009, 4:07 AM
#3
dimmyr avatar

dimmyr

New Zenner

Join Date:
Jun 2008
Posts:
54
Plugin Contributions:
0

Re: geo4zen add-on

Quick update - I just placed the ipcheck.php file in the root of my WIMP server and browsed straight to it, with a blank browser as a result. When I did the same thing on a linux machine, it redirected just fine. Soooo, what is the difference between IIS and Apache that your script doesn't work in IIS?

4 Feb 2009, 4:23 AM
#4
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: geo4zen add-on

I will be at my dev machine in an hour or so and try to help you.

4 Feb 2009, 4:33 AM
#5
dimmyr avatar

dimmyr

New Zenner

Join Date:
Jun 2008
Posts:
54
Plugin Contributions:
0

Re: geo4zen add-on

You rock, Kiddo.

Here is some more snooping that I've done. So I tried to debug the HTTP traffic, and found that on the Linux box the stream lists the Location variable from your script and redirects using 302:

HTTP/1.1 302 Moved Temporarily
Date: Wed, 04 Feb 2009 04:27:11 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.8
Location: http://www.google.com/
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html

But on the IIS box, that "Location:" is missing in the stream:

HTTP/1.1 200 OK
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: PHP/5.2.6
Date: Wed, 04 Feb 2009 04:27:22 GMT
Connection: close
4 Feb 2009, 4:53 AM
#6
dimmyr avatar

dimmyr

New Zenner

Join Date:
Jun 2008
Posts:
54
Plugin Contributions:
0

Re: geo4zen add-on

Ok, more info. I am not a PHP programmer by far. I just cut and paste. So I created a small PHP file with the following code on the root of the IIS site:

<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.google.com/');
?>

And it worked. Which means that the whole IF statement is not working or the script is not parsing the IP CSV site...

4 Feb 2009, 5:13 AM
#7
dimmyr avatar

dimmyr

New Zenner

Join Date:
Jun 2008
Posts:
54
Plugin Contributions:
0

Re: geo4zen add-on

Ok, with a little poking around I have it figured out.

It appears that for IIS, instead of using:

getenv("REMOTE_ADDR")

you have to use:

$_SERVER['REMOTE_ADDR']

I tried it and it worked perfectly with your script. You may wanna publish the disclaimer to your posted module on Zen-cart.com about IIS servers.

For anyone who found this post by searching - if you are running IIS, in the original Kiddo's script, line 6:

instead of:

$addr = getenv("REMOTE_ADDR");

put:

$addr = $_SERVER['REMOTE_ADDR'];

Thank you, Kiddo for this wonderful solution to many of ours' problem.

4 Feb 2009, 5:36 AM
#8
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: geo4zen add-on

HaHa! I get back and go to look at how to help you and You have done it yourself! And provided your notes and documentation to boot!

Bravo!

You are clever to work it out so methodicaly and by test and observe. Most excellent!

Is there anything at all I can do?

Will post an updated version with your notes and IIS instructions.

Or perhaps you would like to package and upload the module? You have added to it's value so you may do that and add your name to the notes and code.

23 Sep 2009, 2:09 AM
#10
mark_deng avatar

mark_deng

New Zenner

Join Date:
Aug 2009
Posts:
2
Plugin Contributions:
0

Re: geo4zen add-on

:smile:

thnx for this module. I used for sometime. It works great. The only thing is I feel is the IP database. not very accurate.

I think if you could incorporate the IP database from http://www.maxmind.com/app/geoip_country. That could be awesome.

PS: this IP database is more accurate.

23 Sep 2009, 2:37 AM
#11
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: geo4zen add-on

Thank you for the pointer. I will look into that DB.

There may also be a newer more up-to-date version of the DB in use. The copy packaged with the mod is probably getting out of date by now. I think there is a pointer in the docs to where to check for an updated DB.

BTW, as soon as I can get my grubby little hands on a copy of ZC v2, I will make sure there is a working version for that release as well.

6 Feb 2010, 4:38 AM
#12
mark_deng avatar

mark_deng

New Zenner

Join Date:
Aug 2009
Posts:
2
Plugin Contributions:
0

Re: geo4zen add-on

Hello,
I have been using the module for some time. I did a trick to route customers from specific regions, let’s say, Thailand, to an error page or to a different site as per the instructions. It does work well. But if you open the website again in the next tab by typing the address without closing the previous tab in the ie/chrome/opera/fx, then the trick fails; you will not see an error page or be routed to a dif site as expected. I think it is cache or something that makes the module in vain.

I would really appreciate if someone could bring out a solution.

Thanks
Mark

21 Oct 2011, 2:29 AM
#13
harry2cool avatar

harry2cool

Zen Follower

Join Date:
Oct 2005
Posts:
280
Plugin Contributions:
0

Re: geo4zen add-on

Great mod.

How to add an exception IP?
Eg: Ban In India, however below exception

120.62.23.142 IN IND India

Thanks

30 Jan 2012, 9:36 AM
#14
davecake avatar

davecake

New Zenner

Join Date:
Jan 2012
Location:
Perth, Western Australia
Posts:
1
Plugin Contributions:
0

Re: geo4zen add-on

A really useful bit of code, I am using it as a starter point to write some per-product blocking code that we need.

Only one problem - got it installed and working, and it immediately told me that I am in Canada (I'm on the other side of the planet). Anyone got anywhere with a better database?