JavaScript Editor Ajax software     Free javascripts 



Main Page

// +----------------------------------------------------------------------+
// | LinkChecker |
// | Gets URL header data using cURL |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 Jaimie Sirovich |
// +----------------------------------------------------------------------+
// | Author: Jaimie Sirovich <jsirovic@gmail.com> |
// +----------------------------------------------------------------------+
class LinkChecker
{
// helper function for the cURL request
function CURLOPT_WRITEFUNCTION($ch, $str)
{
global $LINKCHECKER_total_str;
$LINKCHECKER_total_str .= $str;
if (preg_match(‘/^(.*?)\r\n\r\n/s’, $LINKCHECKER_total_str, $matches))
{
echo $matches[1];
return -1;
}
else
{
return strlen($str);
}
}
// return the header data
function getHeader($url, $userAgent = “Mozilla/4.0”)
{
global $LINKCHECKER_total_str;
$LINKCHECKER_total_str = “”;
ob_start();
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_WRITEFUNCTION,
array(“LinkChecker”, “CURLOPT_WRITEFUNCTION”));
$result = curl_exec($ch);
curl_close($ch);
return ob_get_clean();
}
// return response code
function parseResponseCode($str)
{
preg_match(‘/^HTTP\/\d\.\d (.{3})/‘, $str, $matches);
return (isset($matches[1]) ? $matches[1] : ‘(not available)‘);
}
255
Chapter 13: Coping with Technical Issues
c13.qxd:c13 10:45 255


JavaScript Editor Ajax software     Free javascripts