Skip to main content
1 of 5
Harikrishnan
  • 9.9k
  • 11
  • 87
  • 128

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

How can I detect This error using php curl? curl return success even if URL does not exist.

  Not Found

The requested URL /ezlogins/index.php/servers/edit was not found on this 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);

    }
Harikrishnan
  • 9.9k
  • 11
  • 87
  • 128