Alright, the code posted second just displays a bunch of
h on the screen.
As for the code that was being buggy:
Code: Select all
<?php
function getRemoteFile($url)
{
// get the host name and url path
$parsedUrl = parse_url($url);
$host = $parsedUrl['host'];
if (isset($parsedUrl['path'])) {
$path = $parsedUrl['path'];
} else {
$path = '/';
}
if (isset($parsedUrl['query'])) {
$path .= '?' . $parsedUrl['query'];
}
if (isset($parsedUrl['port'])) {
$port = $parsedUrl['port'];
} else {
// most sites use port 80
$port = '80';
}
$timeout = 10;
$response = '';
// connect to the remote server
$fp = @fsockopen($host, '80', $errno, $errstr, $timeout );
if( !$fp ) {
echo "Cannot retrieve $url";
} else {
// send the necessary headers to get the file
fputs($fp, "GET $path HTTP/1.0\r\n" .
"Host: $host\r\n" .
"User-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\n" .
"Accept: */*\r\n" .
"Accept-Language: en-us,en;q=0.5\r\n" .
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" .
"Keep-Alive: 300\r\n" .
"Connection: keep-alive\r\n" .
"Referer: 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;
}
$result = getRemoteFile($_GET['path']);
preg_match_all("/<img.*?src=\"([^\"]+)/im", $result, $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
?>
Outputs:
Code: Select all
Array
(
[0] => Array
(
[0] => Array
(
[0] => images/logo_top.png
[1] => images/buttons/home_on.png
[2] => images/buttons/about.png
[3] => images/buttons/members.png
[4] => images/buttons/register.png
[5] => images/buttons/search.png
[6] => images/buttons/statistics.png
[7] => images/buttons/contact.png
[8] => images/buttons/tutorial.png
[9] => images/buttons/forums.png
[10] => images/mysql_powered.png
[11] => images/pwrd_apache.gif
[12] => images/icon_mini-xml.png
[13] => images/php-power-micro2.png
[14] => images/linux_powered.gif
[15] => images/loadtime.gif
[16] => images/queries.gif
[17] => images/gzip.gif
[18] => images/icon_user.gif
[19] => images/load.gif
)
)
Note here is the real output I am getting (screenshot because i cant copy and paste dead images):

(Note the blue question mark boxes are the images that are not displaying, thats how Safari displays dead images)
And the "image source" for the images that are not displaying are like:
Code: Select all
http://localhost/~steve/images/logo_top.png%20%20%20%20%20%20%20%20%20%20%20%20[1]%20=%3E%20%3Cimg%20src=
Where it should be: