通常在網址標頭進行
「熱鏈」檢測。您的示例不會發送引薦來源,所以遠程端會假設它是直接請求。
您可以使用stream_context_set_default()將引用標頭添加到get_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測試了它,它按預期工作。下面的輸出:
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
其中u已經測試可以ü請給直播網址鏈接,我就來了200只 – Priya
我已經編輯我上面的帖子,使之更加冗長,但我只是用你提供的網址。 –
如果它不適用於您...您使用的是哪個版本的PHP? –