Closed (fixed)
Project:
IP to Country
Version:
6.x-1.1
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
30 Aug 2009 at 04:08 UTC
Updated:
9 Oct 2009 at 14:50 UTC
Sorry if this is too dumb, I'm no programmer. To begin, I just want to print the country code of the visitor. I tried this 3 scripts on page.tpl.php but I can't get it to work:
<?php
$addr = $_SERVER['REMOTE_ADDR'];
$country = module_invoke('ip2cc', 'get_country', $addr);
print_r($country->country_code2);
print_r($country->country_code);
?>
<?php
$co = ip2cc_get_country($_SERVER['REMOTE_ADDR']);
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);
print_r(theme("ip2cc_flag", $co,$_SERVER['REMOTE_ADDR']));
print_r(theme("ip2cc_ip_flag",$_SERVER['REMOTE_ADDR']));
print_r(theme("ip2cc_ip_flag_long",$_SERVER['REMOTE_ADDR']))
?>
<?php
$co2=module_invoke('ip2cc','get_country',$_SERVER['REMOTE_ADDR']);
print($co2->country_code);
?>
I just get nothing printed.
Is my code wrong? Or am In doing something else wrong?
I'll appreciate any advice or simple example on how to print visitor's country code.
Thanks
Comments
Comment #1
federico commentedI just want to mention that ip2cc table is correctly imported (I checked it using phpmyadmin)
Comment #2
mrfelton commentedIf that doesn't work then I'd say to get the latest -dev code, reinstall the module and try again. Are you running this on your local machine? If so, your IP address would be reported as 127.0.0.1 (localhost), and so it wouldn't tie that to any country. Try visiting http://www.whatismyip.com/ and check what your external IP address is. Then, use that in the ip2cc_get_country() function. Try using the devel module to show you exactly what is being returned by the function (install the devel module, and then use dsm($cc) to show you the details - it does the same as print_r() but in a much more readable way.)
Comment #3
federico commentedThanks for your reply. I tried this on a live site using latest dev and it didn't work. I just get nothing printed. I also installed devel module and tried dsm($cc), and got an empty message.
I close this request since I can't give more info and have no skills to investigate further. I'll wait for next release to try it again.