如果您仅需要在网站内部使用引荐来源信息(即:网站页面之间,而不是外部),则可以手动跟踪用户的引荐来源信息.
// Get the full URL of the current page
function current_page_url(){
$page_url = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){
$page_url .= 's';
}
return $page_url.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
/* (Assuming session already started) */
if(isset($_SESSION['referrer'])){
// Get existing referrer
$referrer = $_SESSION['referrer'];
} elseif(isset($_SERVER['HTTP_REFERER'])){
// Use given referrer
$referrer = $_SERVER['HTTP_REFERER'];
} else {
// No referrer
}
// Save current page as next page's referrer
$_SESSION['referrer'] = current_page_url();
然后,要访问引荐来源,只需使用$referrer变量.
if(isset($referrer)){
echo 'Referred from "'.$referrer.'"';
echo 'Back';
} else {
echo 'No referrer';
}
这样一来,如果用户访问http://www.example.com/page_1.php,他们会看到引荐来源的信息,如果他们的浏览器提供了它,否则没有引用.然后,当他们访问http://www.example.com/page_2.php以及您网站的任何后续页面时,引荐来源网址将可访问.