You can set the session variable as $ _SESSION ['lang'], and apply this code only if $ _SESSION ['lang'] is not set. I mean:
if(!isset($_SESSION['lang'])){ if(preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT'])){ $_SESSION['lang'] = 'en'; header("location:index.php"); }else{ $_SESSION['lang'] = 'other'; header("location:http://cn.gearor.com"); } }
Sinan source share