<?php
function remote_file_exists ($domein, $path, $port = 80, $get = false)
{
	$path = (substr($path, 0, 1) != '/') ? '/'.$path : $path;
	
	$sock = fsockopen($domein, $port, $errno, $errstr, 5); //5s timeout
	if (!$sock)
		return false;
	
	$cmd = ($get === true) ? "GET ".$path." HTTP/1.1\r\n" : "HEAD ".$path." HTTP/1.1\r\n";
	$cmd .= "Host: ".$domein."\r\n";
	$cmd .= "Connection: Close\r\n\r\n";
	
	fwrite($sock, $cmd);
	$output = NULL;
	while (!feof($sock))
		$output .= fgets($sock, 128);
	
	fclose($sock);
	
	if(preg_match('#HTTP/1.1 200 OK#', $output))
		return true;
	else
		return false;
}