Parsing HTTP status codes for interacting with API

Trent

New Member
I'm building a script in PHP to interact with an API and need to be able to parse the HTTP status code the API is giving me. For the most part, it gives one of the following responses:\[code\]HTTP/1.1 401 UnauthorizedHTTP/1.1 403 Forbidden HTTP/1.1 404 Not Found HTTP/1.1 410 Gone \[/code\]I need to be able to recognize which response is being given, and, if its 401 or 410, to keep going, but, if it's 401 or 403, to keep track and to shut down the script after a few in a row (because I've exceeded my call limit for the day).My code is pretty simple:\[code\]for($i = $start;$i < $end;$i++){ // construct the API url $url = $base_url.$i.$end_url; // make sure that the file is accessible if($info = json_decode(file_get_contents($url))) { // process retrieved data } else { // what do I put here? }}\[/code\]My problem is I don't know what to put in the 'else' loop. I'm using the CodeIgniter framework, if anyone knows of any shortcuts to use. Also, I'm open to using cURL, but never have before.
 
Back
Top