Skip to content

Instantly share code, notes, and snippets.

@girvan
Created March 22, 2012 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girvan/2155465 to your computer and use it in GitHub Desktop.
Save girvan/2155465 to your computer and use it in GitHub Desktop.
<?php
//input可以是單一字串,或是array
function must_referer($src){
$src_arr=Array();
if(empty($_SERVER['HTTP_REFERER'])) //一定要有referer url
exit;
$src_arr=(is_array($src))?$src:Array($src);
foreach($src_arr as $url)
if(strpos($_SERVER['HTTP_REFERER'],$url)===0) //一定要match到,而且是第一個字元就要match到
return; //有match到,就結束這個function
exit; //都沒有match到,將整支程式結束掉
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment