تفضل
كود PHP:
function getRemoteFile($url)
{
// get the host name and url path
$parsedUrl = parse_url($url);
$host = $parsedUrl['host'];
// the url is pointing to the host like http://www.mysite.com
$path = (isset($parsedUrl['path']) ? $parsedUrl['path'] : '/') . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '');
// most sites use port 80
$port = isset($parsedUrl['port']) ? $parsedUrl['port'] : 80;
$timeout = 10;
$response = '';
// connect to the remote server
$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ($fp)
{
// send the necessary headers to get the file
fputs($fp, "GET $path HTTP/1.0\r\nHost: $host\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3\r\nAccept: */*\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection: keep-alive\r\nReferer: http://$host\r\n\r\n");
// retrieve the response from the remote server
while ($line = fread($fp, 4096))
$response .= $line;
fclose($fp);
// strip the headers
$pos = strpos($response, "\r\n\r\n");
$response = substr($response, $pos + 4);
}
// return the file content
return $response;
}