问题
I'm working on "CDN" video delivery script. my problem is not all providers are included, therefor I need to check if the client can access the link, if not send him another one. i've tried with get_headers, but with get_headers only the server checks if it can access the link, not the user.
$header = get_headers($VIDEO);
preg_match('/\d{3}/', $header[0], $code);
if($code[0] < 400){
header("Content-type: video/x-flv");
header("Location:" . $VIDEO . $dop);
}else{
header("Content-type: video/x-flv");
header("X-Accel-Redirect: /".$_GET["filename"].$dop);
}
回答1:
Try something like this:
$ip_address = array('50.101.20.212', '25.65.659.25');
if(in_array($_SERVER['REMOTE_ADDR'], $ip_address )){
// may access site;
}else{
// access denied
}
UPDATE
You may do the opposite way to find out whether the user may enter the link or not,
$ip_address = array('50.101.20.212', '25.65.659.25');
if(!in_array($_SERVER['REMOTE_ADDR'], $ip_address )){
//access denied
}
来源:https://stackoverflow.com/questions/15478896/check-if-client-can-access-the-page-if-not-do-something