what correct/best way check headers file_get_contents function? example code i'm using right based on riot's api league of legends stats:
$summonername = htmlspecialchars($_post["main_summoner"]); $url = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . $summonername . '?api_key=' . $apikey); $result = json_decode($url, true); $summoner = $result[$summonername]['name'];
i know how turn headers array using
$http_response_header
but correct way find extract first header , check value? compare first value in array 404 error instance or need check if string contains keyword? correct way go this?
edit here new/working code
$url1 = "https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/" . $summonername . "?api_key=" . $apikey; $ch = curl_init(); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_url,$url1); $result=curl_exec($ch); $httpcode = curl_getinfo($ch, curlinfo_http_code); curl_close($ch);
and check httpcode with:
if($httpcode !== 404) {
Comments
Post a Comment