المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : [دالة] get_headers في الphp4



walid_8281500
03-19-2009, 08:15 PM
بسم الله الرحمن الرحيم
بصراحة ترددت جدا اني احط الدالة دي بسبب ان معظم الHosters رقوا للphp5 و لكن مش مهم يمكن واحد يستفيد منها و خلاص الدالة دي للعلم من اجمل الدوال اللي شفتها في الphp5 هيا بتجيب الheaders و ... بس http://traidnt.net/vb/images/smilies/shiny01.gif




<?php



/**
* Replace get_headers()
* @author Ahmed H AboElnasser <support@egysolutions.net>
* @since PHP 5.0.0
* @require PHP 4.0.0 (user_error)
*/

if (!function_exists('get_headers')) {
function get_headers($url, $format = 0)
{
// Init
$urlinfo = parse_url($url);
$port = isset($urlinfo['port']) ? $urlinfo['port'] : 80;

// Connect
$fp = fsockopen($urlinfo['host'], $port, $errno, $errstr, 30);
if ($fp === false) {
return false;
}

// Send request
$head = 'HEAD ' . $urlinfo['path'] .
(isset($urlinfo['query']) ? '?' . $urlinfo['query'] : '') .
' HTTP/1.0' . "\r\n" .
'Host: ' . $urlinfo['host'] . "\r\n\r\n";
fputs($fp, $head);

// Read
while (!feof($fp)) {
if ($header = trim(fgets($fp, 1024))) {
list($key) = explode(':', $header);

if ($format === 1) {
// First element is the HTTP header type, such as HTTP 200 OK
// It doesn't have a separate name, so check for it
if ($key == $header) {
$headers[] = $header;
} else {
$headers[$key] = substr($header, strlen($key)+2);
}
} else {
$headers[] = $header;
}
}
}

return $headers;
}
}

?>