Built From Developers For Developers
» Kuikie.com » Snippets » PHP » PHP. Checking If URL Exists
  Categories
  PHP
    Arrays
    Date & Time
    Files & Directories
    Globalization
    Images
    OOP
    Other
    Strings
    User Interface
 

PHP. Checking If URL Exists

This is a simple function written in PHP to quickly check if an URL exists.

//======================== START OF FUNCTION ==========================//
// FUNCTION: url_exists                                                //
//=====================================================================//
function url_exists($url) {
    $headers = @get_headers($url);
    $response_code = substr($headers[0], 9, 3);
    if ($response_code == '200' or $response_code == '304') {
        return true;
    }
    return false;
}
//=====================================================================//
//  FUNCTION: url_exists                                              //
//========================= END OF FUNCTION ===========================//
 
©2012 Sinevia Ltd Terms of Use         Privacy Policy Valid XHTML 1.0 Transitional