Revision: 22216
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 6, 2010 05:25 by ginoplusio
Initial Code
function url_exists($url) { $ch = @curl_init($url); @curl_setopt($ch, CURLOPT_HEADER, TRUE); @curl_setopt($ch, CURLOPT_NOBODY, TRUE); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $status = array(); preg_match('/HTTP\/.* ([0-9]+) .*/', @curl_exec($ch) , $status); return ($status[1] == 200); }
Initial URL
http://www.barattalo.it/2010/01/06/test-if-a-remote-url-exists-with-php-and-curl/
Initial Description
If you have to test if a remote url is correct you can use CURL and get the headers returned by the http request. If you receive a 200 code, than it’s ok, else the url is not correct:
Initial Title
Url exists function to check remote url
Initial Tags
Initial Language
PHP