Hello, i am dynamically loading a website via file_get_contents with the following script.
<?php
header('Content-Type: text/html; charset=iso-8859-1');
$url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}";
$base_url = explode('/', $url);
$base_url = (substr($url, 0, 7) == 'http://') ? $base_url[2] : $base_url[0];
if (file_get_contents($url) != false) {
$content = @file_get_contents($url);
// $search = array('@(<a\s*[^>]*href=[\'"]?(?![\'"]?http))@', '|(<img\s*[^>]*src=[\'"]?)|');
// $replace = array('\1proxy2.php?url=', '\1'.$url.'/');
// $new_content = preg_replace($search, $replace, $content);
function prepend_proxy($matches) {
$url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}";
$prepend = $matches[2] ? $matches[2] : $url;
$prepend = 'http://h899310.devhost.se/proxy/proxy2.php?url='. $prepend .'/';
return $matches[1] . $prepend . $matches[3];
}
function imgprepend_proxy($matches2) {
$url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}";
$prepend2 = $matches2[2] ? $matches2[2] : $url;
$prepend2 = $prepend2 .'/';
return $matches2[1] . $prepend2 . $matches2[3];
}
$new_content = preg_replace_callback(
'|(href=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i',
'prepend_proxy',
preg_replace_callback(
'|(src=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i',
'imgprepend_proxy',
$content
)
);
echo "<base href='http://{$base_url}' />";
echo $new_content;
} else {
echo "Sidan kan inte visas";
}
?>
Now the problem is that some pictures doesn't show in websites. For example those sites who does have CSS links. It is a CSS problem i think.
You can test the script here to see what i mean:
http://h899310.devhost.se/proxy/index.html
How can I fix this?