Check for valid (not dead) links using PHP
function is_available($url, $timeout = 30) {
$ch = curl_init(); // get cURL handle
$opts = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_NOBODY => true
CURLOPT_TIMEOUT => $timeout
);
curl_setopt_array($ch, $opts);
curl_exec($ch);
$retval = curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200;
curl_close($ch);
return $retval;
}
Written by Miloš Matić
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#