/ Published in: PHP
URL: http://www.barattalo.it/2010/01/06/test-if-a-remote-url-exists-with-php-and-curl/
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:
Expand |
Embed | Plain Text
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); return ($status[1] == 200); }
You need to login to post a comment.
