You are here

function block_country_boot in Block Country 7

Implements hook_boot().

File

./block_country.module, line 28
Country_Block - Module for showing the country specific blocks.

Code

function block_country_boot() {
  if (!isset($_SESSION['user_country_code'])) {

    // We need ip2country_get_country() so make sure it gets loaded.
    drupal_load('module', 'ip2country');

    // Create a session variable to store user country.
    $_SESSION['user_country_code'] = '';

    // Get user IP address.
    $ip = ip_address();

    // Get country code based on user IP address.
    $country_code = ip2country_get_country($ip);

    // Set country code, if not set default.
    $_SESSION['user_country_code'] = !empty($country_code) ? $country_code : variable_get('site_default_country', 'IN');
  }
}