取得HTTP錯誤代碼方式?
code
<?php
$url = "https://covid19dashboard.cdc.gov.tw/dash3";
$resutlt1 = file_get_contents($url);
$resutlt1_json = json_decode($resutlt1, true);
print_r("確診: ".$resutlt1_json[0]["確診"]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result2 = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result2_json = json_decode($result2, true);
print_r("\nstatusCode:".$httpcode);
print_r("\n送驗: ".$result2_json[0]["送驗"]);
curl_close($ch);
result
確診: 467
statusCode:200
送驗: 81,587
哈囉你好~
我有試著找到一些資料不知道確定是不是你需要的...
但希望可以幫助到你~
(https://blog.hoyo.idv.tw/?p=3036)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $m3u8);
curl_setopt($ch, CURLOPT_REFERER, 'http://hichannel.hinet.net/radio/index.do' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
// 不可用資源回傳 410
if ( $info['http_code'] == '200' ) {
echo $m3u8;
break;
}
else {
//echo $m3u8;
echo $i++;
//sleep(1);
}