Changing blocks based on visitor's country On a Drupal 6 site I am trying to display blocks on my site based on user's country.


To do this I had to install  'IP to Country' module
Updated IP to Country
Created a new block and added the following code into the block body to print the user's country code:

&lt;?php
$co=module_invoke('ip2cc','get_country',$_SERVER['REMOTE_ADDR'];);
print($co-&gt;country_code);
?&gt;

Then, under 'Show block on specific pages' selected 'Show if the following PHP code returns TRUE (PHP-mode, experts only).' and then added the below mentioned code, so that the block is displayed based on the country ID.

&lt;?php $co-&gt;country_code == "IN" ?&gt;



After doing all these the block is getting disabled for the ID mentioned, eg: If 'IN' is mentioned the block should only be displayed for Indian visitors, but the block is actually being disabled.
Your code seems to be right. You've mis-spelled the module name in the module_invoke function at #3 and misplaced the semicolon ;

Try this:

&lt;?php

$detectedcountry = module_invoke('ip2country','get_country',$_SERVER['REMOTE_ADDR']);
$us_canada = array(
  'US','CA'
);

//return true in block visibility when the country appears to be in detected country
if(in_array($detectedcountry,$us_canada)){
  return true;
} 

?&gt;