这样大家看得清楚些
<?php
Function GetName($strFileName,$strLn)

ob_start();
$strtem  = $strFileName;
$pos1 =  stripos ($strtem,".");
$tail = "";
if ($pos1 > 0)

$tail = stristr ($strtem,".");  //保存.html 这样的扩展名
$strtem = substr($strtem,0,$pos1);
}
$pos1 =  stripos($strtem,"_") ;  //去掉 _en, _hk 这样的尾缀
if ($pos1 > 0)
{
$strtem = substr($strtem,0,$pos1);
}
return $strtem.$strLn.$tail;
}
$SourceUrl = getenv("HTTP_REFERER");
$pos1 = stristr ($SourceUrl,"/");
while ($pos1) {
$pos2 = substr($pos1,1);
$pos1 = stristr ($pos2,"/");
}
$ExpireTime = mktime(0,0,0,1,1,2100); //到2100年1月1日失效
switch ($_GET['ln'])
{
case "cn": // 
if ($pos2==""):
$newUrl = $SourceUrl;
else:
$newUrl =  substr($SourceUrl,0,strlen($SourceUrl)-strlen($pos2)).GetName($pos2,"_cn");
endif;
setcookie("ln","cn",$ExpireTime,"/");//不带失效时间
break;
case "hk":
if ($pos2==""):
$newUrl = $SourceUrl;
else:
$newUrl = substr($SourceUrl,0,strlen($SourceUrl)-strlen($pos2)).GeTName($pos2,"_hk");
endif;
setcookie("ln","hk",$ExpireTime,"/");//不带失效时间
break; 
case "en": 
if ($pos2==""):
$newUrl = $SourceUrl;
else:
$newUrl = substr($SourceUrl,0,strlen($SourceUrl)-strlen($pos2)) .GeTName($pos2,"_en");
endif;
setcookie("ln","en",$ExpireTime,"/");
break;
default:
$newUrl = $SourceUrl;
break;
}
header("location:".$newUrl); // 返回其调用页面
ob_end_flush();
exit();
?>