IP to Country Demonstration


207.241.237.222
us
US
USA
United States
AS174 proxy-registered route by Cogent
174

Sample Code?

Should be nice to see some sample code to use the API. This is very good if you want the module to be used by less-programming-skilled webmasters.....

sample code for ip2cc

Sorry for lately reply. I was so busy last week. ip2cc provides a few APIs for you to call as follow. $co = ip2cc_get_country("203.150.224.25"); print_r($co->country_code2); print_r($co->country_code3); print_r($co->country_name); print_r($co->net_name); print_r($co->as_number); Otherwise, you may pass the country object to theming functions as below. print_r(theme("ip2cc_flag", $co, "203.150.224.25")); print_r(theme("ip2cc_ip_flag", "203.150.224.25")); print_r(theme("ip2cc_ip_flag_long", "203.150.224.25"))

error

hi the program is not so exact, as i'd like, because i've a hungarian IP, and its say, this IP is from Romania ... :(

sorry about that

Is this your ip? 81.196.141.182 I will correct it in db.

Private Addresses

Maybe you could add the private address ranges (RFC1918). 192.168.0.1 gives me "Oops! not found". Doug

yes, sir!

yes, sir! I will do it.

Doesn't recognize Israeli websites and their IP addresses

For example : www.ynet.co.il (ip = 192.115.80.66) www.nrg.co.il These IP address ranges do not apear in ip2cc table in the database at all.

Oops, not updated version of ipdb

I see that webhosting.info got it right so probably I (as well as your website) haven't got the most updated ipdb...

IF IP = country then...

Hello, can this program be used to do some if ... then operations? For example, I would like to use it to decide if my user should see a banner advertisement (if he comes from Guatemala or the USA) else show him a google adsense ad!!!

sorry

I didn't update ipdb on regular basis. I will find a spare time to do so.

yes

why not! You can add this condition to each block.

How to put output in a block..

I am not a pro in either php or Drupal , I would like to ask how can I output the IP2CC info like flag, IP etc. into the sidebar using a block ??

putting ip2cc in a block

Interesting! You can only do this for each node. In particular, the url must begin by node/.

$path = explode('/',drupal_lookup_path('source',$_GET['q']));
$node = node_load($path[1]);
$co = ip2cc_get_country($node->hostname);
print_r($co->country_code2);
print_r($co->country_code3);
print_r($co->country_name);
print_r($co->net_name);
print_r($co->as_number);

test

test

test

test

Test the IP detect

Testing this out.

Can Views get the information?

I have content on a website... Some for US residents, some for UK residents. Can I pass the browser country information, directly to views, as a argument, to display only nodes with the taxonomy term USA, or if the browser is in the UK. THANKS!!

Post new comment