html - PHP GeoIP loop error -


i'm using php redirection script, gives me continues loop error default redirection 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 loop script executed on every page on every page-load.

you working sessions, convenient way set flag there have checked user:

<?php  //...  // if flag not set if( ! isset($_session['checkedgeoip']) ) {   // set flag here don't need set after each case.   // set requests during session ,    // above if-statement prevent checking , redirecting again   $_session['checkedgeoip'] = true;    // execute geoip logic...   require_once('geoplugin.class.php');   $geoplugin = new geoplugin();   $geoplugin->locate();   $country_code = $geoplugin->countrycode;    switch ($country_code)   {       // ...   }  } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -