Forum Moderators: coopster
$headers = my_get_headers("example.com/adv_check.php" );
if($headers['status'] == 'HTTP/1.1 200 OK'){
$period = 1;
$script_path = $_SERVER[" DOCUMENT_ROOT" ];
$cache_dir = $_SERVER[" DOCUMENT_ROOT" ]." /cache/" ;
$full_path = $_SERVER[" HTTP_HOST" ].$_SERVER[" REQUEST_URI" ];
$full_path = preg_replace('/\/$/', '', $full_path);
$full_path = preg_replace('/^\http:\/\//', '', $full_path);
$full_path = preg_replace('/^\www\./', '', $full_path);
$file = $cache_dir.str_replace (" /" , " _" , $full_path);
$full_path = urlencode($full_path);
$file_name =
'http://example.com/adv_check.php?full_path='.$full_path;
if(is_dir($cache_dir)){
if(is_file($file)){
$mtime = filemtime($file);
$time = time();
$clear_time = mktime(0, 0, 0, date(" m" , $mtime) , date(" d" ,
$mtime)+$period, date(" Y" , $mtime));
if($time > $clear_time)
unlink($file);
}
if(is_file($file)){
$fd = fopen ($file, " r" );
$html_string = fread ($fd, filesize($file));
fclose ($fd);
}else{
//$html_string = @file_get_contents($file_name);
ob_start();
readfile($file_name);
$html_string = ob_get_contents();
ob_end_clean();
if(strlen($html_string) > 3){
$fd = fopen ($file, " w+" );
fwrite ($fd, $html_string, strlen($html_string));
fclose ($fd);
}
}
}else{
//$html_string = @file_get_contents($file_name);
ob_start();
readfile($file_name);
$html_string = ob_get_contents();
ob_end_clean();
}
echo $html_string;
}
function my_get_headers($url) {
$url_info=parse_url($url);
if(isset($url_info['path']))
$path = $url_info['path'];
else
$path = '/';
$port = isset($url_info['port'])? $url_info['port'] : 80;
@$fp=fsockopen($url_info['host'], $port, $errno, $errstr, 10);
if($fp) {
stream_set_timeout($fp, 10);
$head = " HEAD " .$path."?" .@$url_info['query'];
$head .= " HTTP/1.0\r\nHost: " .@$url_info['host']." \r\n\r\n" ;
fputs($fp, $head);
while(!feof($fp)) {
if($header=trim(fgets($fp, 1024))) {
$sc_pos = strpos( $header, ':' );
if( $sc_pos === false ) {
$headers['status'] = $header;
}else{
$label = substr( $header, 0, $sc_pos );
$value = substr( $header, $sc_pos+1 );
$headers[strtolower($label)] = trim($value);
}
}
}
return $headers;
}else{
return false;
}
}
Thanks in advance
[edited by: eelixduppy at 12:39 pm (utc) on July 9, 2007]