$fromHost = array( 'paipai.com', 'localhost', '127.0.0.1' ); $s = 'http://www.paipai.Com/chong/abc.shtml'; $urlArr = parse_url($s); $host = isset($urlArr['host'])?$urlArr['host']:''; $host = strtolower(str_ireplace('www.','',$host)); echo $host.'-->'; echo in_array($host,$fromHost)?'允许通过':'非法来源';
//$referer 为来源网址
$referer = $_SERVER['HTTP_REFERER'];