How can I detect URL Not Found Error in php curl? -


how can detect error using php curl? curl return success if url not exist.

not found requested url /foo/index.php/items/edit not found on server. 

my code

$post_fields = array('info' => json_encode($fields));     curl_setopt($ch,curlopt_url,$url);     curl_setopt($ch,curlopt_post,count($post_fields));     curl_setopt($ch,curlopt_postfields,$post_fields);     curl_setopt($ch,curlopt_returntransfer,true);     curl_setopt($ch,curlinfo_content_type,'application/x-www-form-urlencoded charset=utf-8');      $result = curl_exec($ch);     echo $result;      if(curl_error($ch)){         $result = curl_error($ch);         curl_close($ch);         return $result;     }else{         curl_close($ch);         return json_decode($result,true);      } 

use http status code:

$code = curl_getinfo($ch, curlinfo_http_code); 

if 404, means request url cannot found.

note: remember issue line before curl_close($ch);


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -