title: Geo redirect user just once using php
body: <p>i can use this script easily when users land on site.com/redirect.php
  they get redirected to appropriate TLD according to geo IP
  but when i add this code in 'index.php' it creates a redirect loop.
  Can you help me modify it so that it doesn't create loop. right now this 'break' is not helping..</p>
  
  <pre><code>&lt;?php
  // Next two lines are for Beyond Hosting
  // Don't forget to change your-domain
  require_once '/home/your-domain/php/Net/GeoIP.php';
  $geoip = Net_GeoIP::getInstance('/home/your-domain/php/Net/GeoIP.dat');
  
  // Next two lines are for HostGator
  require_once 'Net/GeoIP.php';
  $geoip = Net_GeoIP::getInstance('GeoIP.dat');
  
  try {
    $country = $geoip-&gt;lookupCountryCode($_SERVER['REMOTE_ADDR']);
  
    switch((string)$country) {
      case 'AU':
        $url = "http://www.site.au";
        break;
      case 'CA':
        $url = "http://www.site.ca";
        break;
      default:
        $url = "http://site.com";
    }
  
    header('Location: '.$url);
  } catch (Exception $e) {
    // Handle exception
  }
  ?&gt;
  </code></pre>