9 January 2017
valid response code 200

You can use PHP cURL functions to check the HTTP status code of a website's header. By using cURL, you can verify that the URL is returning a valid response code of 2xx. This can be adapted to suit different needs, such as detecting a 404 not found error or generating separate error reports for error code 500. Using cURL functions in PHP provides a reliable and flexible solution for ensuring that your website is operating correctly and providing a good user experience.

To perform this check using cURL, you can modify the PHP code as required. For example, you can adjust the code to detect only 404 errors or to generate customized error messages for different HTTP status codes. By utilizing the power of PHP's cURL functions, you can ensure that your website is always functioning at its best and that any errors are quickly identified and addressed.

Source code viewer
  1. function is_working_url($url) {
  2. $handle = curl_init($url);
  3. curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  4. curl_setopt($handle, CURLOPT_NOBODY, true);
  5. curl_exec($handle);
  7. $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
  8. curl_close($handle);
  10. if ($httpCode >= 200 && $httpCode < 300) {
  11. return true;
  12. }
  13. else {
  14. return false;
  15. }
  16. }
Programming Language: PHP