User can't change language after redirection from custom module I'm using custom module to redirect users from Serbia on Serbian language. So, if user comes from Serbia on front page, in URL will be added '/sr'. The problem is that user can't change the language on front page because it always will be redirected.

Can someone help me to fix this issue and make visitor able to change language on front page?

There is the code of custom module:

global $user;
function smart_ip_redirect_init() { 


  if(
    // if country is detected
    !empty($_SESSION['smart_ip']['location']['country_code']) &amp;&amp; 
    // if is front page and anonymous user
    drupal_is_front_page() &amp;&amp; user_is_anonymous()
  ) {
    // load some global variables, language contains information about current language, base_url is base url
    global $language, $base_url;
    // load all active languages
    $languages = language_list();
    // resolve the country code to language, you have to make cases for your needs
    function country_to_language() {
    switch ($_SESSION['smart_ip']['location']['country_code']) {
        case 'RS':
            return 'sr';
        break;

        default:
            return '';
        break;
    }
    }

    // if the URL have no lang parameter
    if(strtoupper(request_uri()) == strtoupper("/")  )
    {
         // does the visitors language exist in our Drupal
      if(array_key_exists(strtolower(country_to_language()), $languages))
      {
        // redirect user to the designated language
        drupal_goto($base_url.'/'.strtolower(country_to_language()));
      }
    }


  }


}
Now your code redirect always, and you only want to redirect once. It means you need implement logic similar to the one below:


Test $_SESSION to see if redirection evaluation took place already. If yes, end.
Create element in $_SESSION, to mark this session as already evaluated against redirection
Decide if you want to redirect or not.
Perform redirect if needed.


That way you will run code responsible for redirection once and only once per user session, and that's seems what you want to do.