JavaScript Editor Ajax software     Free javascripts 



Main Page

// return the MIME type
function parseMimeType($str)
{
preg_match(‘/Content-Type: (.*)/‘, $str, $matches);
return (isset($matches[1]) ? $matches[1] : ‘(not available)‘);
}
// return the Content-Length
function parseContentLength($str)
{
preg_match(‘/Content-Length: (.*)/‘, $str, $matches);
return (isset($matches[1]) ? $matches[1] : ‘(not available)‘);
}
// return the Location
function parseLocation($str)
{
preg_match(‘/Location: ?([^\r\n]*)/i’, $str, $matches);
return (isset($matches[1]) ? $matches[1] : ‘(not available)‘);
}
// return the path to the destination URL
function getPath($url, &$_response_code, $userAgent = ‘Mozilla/4.0’)
{
$_url = $url;
$path = array();
$path[] = ‘Initial destination ‘ . $_url;
$iterations = 0;
do
{
$_buffer = LinkChecker::getHeader($_url);
if (!$_buffer)
{
$path[] = ‘ERROR: Maximum number of redirections exceeded; aborting.’;
break;
}
$_url = LinkChecker::parseLocation($_buffer) ?
LinkChecker::parseLocation($_buffer) : $_url;
$_response_code = LinkChecker::parseResponseCode($_buffer);
$path[] = ($_response_code != 200 && $_response_code != 404) ?
(‘Redirect (‘ . $_response_code . ‘) to => ‘ . $_url) :
(‘Final destination (‘ . $_response_code . ‘) ‘ . $_url );
$iterations++;
if ($iterations > 10)
{
$path[] = ‘ERROR: Maximum number of redirections exceeded; aborting.’;
break;
}
}
while ($_response_code != ‘200’ && $_response_code != ‘404’);
256
Chapter 13: Coping with Technical Issues
c13.qxd:c13 10:45 256


JavaScript Editor Ajax software     Free javascripts