Curl responses in php

  • 17 May, 2023
  • In Curl

Curl responses in php

Curl responses in php

When curl gives success response


    $result = curl_exec($curl);
    $response = json_decode($result, true);

When curl gives error, and one have to find out the exact errors


    if(curl_exec($ch) === false)
    {
        echo 'Curl error: ' . curl_error($ch);
    }
    else
    {
        echo 'Operation completed without any errors';
    }

When one have to find the response code


    $result = curl_exec($curl);
    $response = json_decode($result, true);
    
    $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if($httpcode == '401'){
        echo "window.location.href = '#';";
    }else{
        return $response;
    }

0 Comment's

Add Comment

Register to Reply

About Author

I am Bhawesh Bhaskar, a Full Stack Sr. Software Developer. I am a good learner and always eager to learn new technologies. I can develop both client and server software. In addition to mastering HTML and CSS, I also know how to: Program a browser (like using JavaScript, jQuery) Program a server (like using Laravel, Code Ignitor or Core PHP).