This howto shows you a easy solution to display / not display Drupal blocks based on the location of the user (location based display of Drupal content) with the help of the Drupal Smart IP module. Smart IP identify visitor's geographical location (longitude/latitude), country, region, city and postal code based on the IP address of the user.
Step 1: Install and configure the module Smart IP
The module Smart IP allows you to identify the users location with a very broad range of data sources.
https://www.drupal.org/project/smart_ip
Install the module, choose a method and configure the module accordingly.
Create a block and apply PHP code
Create a block, change the text format to "PHP code" and add the following PHP code:
<?php
$smart_ip_session = smart_ip_session_get('smart_ip');
if ($smart_ip_session['location']['country_code'] == 'XX') {
echo '';
print "This Image block only displays in the country XX";
}
?>
"XX" represents the country code to be changed. You can add multiple country codes, allowing you to define in which countries the Drupal block shall be shown. You can add any PHP commands after the if logic to display or execute whatever you want. You can also change the logic to "if not" allowing you to not display the Drupal block in certain countries.
- Log in to post comments