Heim >Backend-Entwicklung >PHP-Tutorial >php 获取来路[前一页]页面分析函数_PHP教程
php 获取来路[前一页]页面分析函数
本文章提供一款功能全面的获取上一级页面的函数哦,就是来路函数了。
function getref(&$ref,&$fullref) {
global $err,$conf,$HTTP_GET_VARS,$_GET;
if(isset($_GET['anr'])) $refer=$_GET['anr'];
elseif(isset($HTTP_GET_VARS['anr'])) $refer=$HTTP_GET_VARS['anr'];
else $refer='undefined';
if(empty($refer)) $refer='undefined';
if(!strcmp($refer,'null')) $refer='undefined';
$refer=urldecode($refer);
$refer=modsec($refer);
$refer=txtproc($refer);
//to correct back slashes http://111cn.cnindex
$refer=str_replace("","/",$refer);
//to remove unnecessary points http://111cn.cn.
$refer=preg_replace("//./",'/',$refer);
$refer=preg_replace("/.//",'/',$refer);
$refer=preg_replace("/.*$/",'',$refer);
$refer=preg_replace("/("|')*$/",'',$refer);
//to remove unnecessary duplicates of slashes http://111cn.cn///
$refer=preg_replace("/([^:])(/)+/",'$1/',$refer);
$fullref=$refer;
$refer=preg_replace("/^(https?://)(www.)?/i",'',$refer);
$ref=preg_replace("/[?|&|#|;].*$/i",'',$refer);
$ref=preg_replace("/(/)*$/",'',$ref);
$ref=trim($ref);
$ref=preg_replace("/.*$/",'',$ref);
$ref=preg_replace("/("|')*$/",'',$ref);
$ref=trim($ref);
//check referrer (bad)
if(empty($ref)) $ref='undefined';
//search "." in domain name
if(!preg_match("/^([^./]+.)+([^./])+/i",$ref)) $ref='undefined';
}
}