php get the origin [previous page] page analysis function
This article provides a comprehensive function to get the previous page, which is the origin function.
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';
}
}