Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 热链接保护检查头200即将到来,但页面已被保护_Php_Http Headers_Hotlinking - Fatal编程技术网

Php 热链接保护检查头200即将到来,但页面已被保护

Php 热链接保护检查头200即将到来,但页面已被保护,php,http-headers,hotlinking,Php,Http Headers,Hotlinking,您好,我想检查图像是否受热链接保护。我搜索了几个站点,发现http头是检查这个的最佳解决方案,但当我实现时,我发现它给出了错误的结果 例如,http头响应即将到来 Array ( [0] => HTTP/1.1 200 OK [1] 但是,当我在iframe中链接或直接在php中链接时,其抛出错误为.access denied,因此图像受到热链接保护。我正在尝试这个图像链接 <?php $url = 'http://s.wallpaperhere.com/thum

您好,我想检查图像是否受热链接保护。我搜索了几个站点,发现http头是检查这个的最佳解决方案,但当我实现时,我发现它给出了错误的结果

例如,http头响应即将到来

  Array ( [0] => HTTP/1.1 200 OK [1]
但是,当我在iframe中链接或直接在php中链接时,其抛出错误为.access denied,因此图像受到热链接保护。我正在尝试这个图像链接

  <?php
     $url = 'http://s.wallpaperhere.com/thumbnails/preview/20130702/51d3b5478d616.jpg';
     print_r(get_headers($url));
     print_r(get_headers($url, 1));
  ?>

有没有最好的方法来检查这一点并将正确的图像存储在未受保护的数据库中

“热链接”检测通常在referer头上执行。您的示例不会发送推荐人,因此远程端假定这是一个直接请求

您可以使用stream\u context\u set\u default()将referer头添加到get\u headers()调用中。下面的例子。实际上甚至不需要更改我提供的标题值。。。我认为它可以是任何东西

<?php
$default_opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Referer: http://www.fakesite.com/hotlink-check/",
  )
);

stream_context_set_default($default_opts);

$url = 'http://s.wallpaperhere.com/thumbnails/preview/20130702/51d3b5478d616.jpg';
print_r($headers = get_headers($url, 1));

if (preg_match('/200 OK$/', $headers[0])) {
        echo 'OK';
}
else {
        echo 'Not OK';
}

在你测试过的地方,你能给我一个实时的url链接吗?就快200了。我已经编辑了我上面的帖子,让它更详细,但我只是使用你提供的url。如果它不适合你。。。你使用的是哪个版本的PHP?很好用。你能告诉我如何只输出403200以便我可以过滤掉它吗?如果($header='200){echo'ok';}否则{echo'notok';}
Array
(
    [0] => HTTP/1.1 403 Forbidden
    [Server] => cloudflare-nginx
    [Date] => Wed, 18 Dec 2013 16:57:54 GMT
    [Content-Type] => text/html; charset=UTF-8
    [Connection] => close
    [Set-Cookie] => __cfduid=de5cd2750b3e7c528e277df1e584c3a6c1387385874336; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.wallpaperhere.com; HttpOnly
    [Cache-Control] => max-age=10
    [Expires] => Wed, 18 Dec 2013 16:58:04 GMT
    [CF-RAY] => ded65129fde0610
)
Not OK