Curl responses in php

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

Looking for a reliable and skilled web developer? I'm Bhawesh Bhaskar, a Senior Full Stack Software Developer with proven expertise in both front-end and back-end development. I provide professional website design, custom web application development, and robust PHP solutions using Laravel, CodeIgniter, and Core PHP. I help businesses create modern, responsive, and high-performance websites that drive results. Whether you're starting from scratch or need to upgrade your existing site, I deliver solutions tailored to your goals.
💼 Let’s build something great together — contact me today for a free consultation!