PHP GeoIP循环错误

i'm using a php redirection script, it gives me a continues loop error for the default redirection this is the code

<?php
// ccr.php - country code redirect
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
$country_code = $geoplugin->countryCode;
switch($country_code) {
case 'US':
header('Location: http://www.domain.com/en');
exit;
case 'FR':
header('Location: http://www.domain.com/fr');
exit;
case 'BE':
    header('Location: http://www.domain.com/fr');
exit;


default: // exceptions
    header('Location: http://www.domain.com');
exit;
}
?>

The reason you're stuck in a loop is that your script is probably executed on every page an on every page-load.

You are most likely working with sessions, so the most convenient way would be to just set a flag there that you have already checked this user:

<?php

//...

// Do this only if the flag is not set
if( ! isset($_SESSION['checkedGeoIp']) )
{
  // Set the flag here so you don't need to set it after each case.
  // Now this will be set for all requests during the session and 
  // the above if-statement will prevent from checking and redirecting again
  $_SESSION['checkedGeoIp'] = true;

  // Execute the GeoIP logic...
  require_once('geoplugin.class.php');
  $geoplugin = new geoPlugin();
  $geoplugin->locate();
  $country_code = $geoplugin->countryCode;

  switch ($country_code)
  {
      // ...
  }

}