check if client can access the page, if not do something

为君一笑 提交于 2019-12-24 20:27:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!