<?php

//ģʽʾ󱨸棬ʾ֪ͨ
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
//ģʽʾκδ󱨸
error_reporting(0);

//Ҫжϵվб
//ȫСдעǰ治Ҫhttp://
//ȫƥ䣬֧ͨҪͨĿȥд֧
$domain_list = array("cenfun.com", "bbs.cenfun.com", "www.cenfun.com");

//беǷΪΪ(Ĭ)
//ֻЩԴ
//ǲЩԴ
$is_black_list = FALSE;

//ǷԴ(Ĭ)ԴҳΪʱͨҪȷԴַ
//ֱӴûrefererFirefoxУwmpУܲһÿζrefererԴַ
$allow_empty_referer = TRUE;


//ص==================================================================

//ɹ֤ͨҪõĳҪд
function succeed() {
	
	echo "welcome";
	
}

//û֤ͨҪõĳ򣬱緵һҳ棬򷵻һϢһб
function error() {
	
	echo "error";
	
}


//Դҳж===============================================================
//ȡ÷Դĵַ
$referer = $_SERVER["HTTP_REFERER"];	
if($referer) {
	//Դַ
	$refererhost = parse_url($referer);
	//Դַ
	$host = strtolower($refererhost['host']);
	if($is_black_list) {
		//Ǻ
		if (in_array($host, $domain_list)) {
			error();
		} else {
			succeed();
		}
	} else {
		//ǰ
		if($host == $_SERVER['HTTP_HOST'] || in_array($host, $domain_list)) {
			succeed();
		} else {
			error();
		}
	}
} else {
	if ($allow_empty_referer) {
		succeed();
	} else {
		error();
	}
}

?>
