Hi,
We have to include in our own web sitepartner's catalog developped in ASP.
To do this we are using the script above.
We still have a problem due to relative links and images links.
Any idea to solve this trouble?
<?
$url = "http://www.partnerwebsite.com/folder/";
$maxtries = 5;
$tries = 0;
$redirecting = true;
while ($redirecting && $tries < $maxtries)
{
$tries++;
// get host name and URI from URL, URI not needed though
preg_match("/(http:\/\/)?([\/]+)(.+)/i", $url, $matches);
$host = $matches[2];
$uri = $matches[3];
$connection = fsockopen($host
,80,&$errorNumber,&$errorString,10);
if ($connection)
{
//tell server what document we want
fputs ($connection, "GET $url HTTP/1.0");
fputs ($connection, "\r\n");
//Host isn't required by HTTP/1.0 but some sites complain otherwise
fputs ($connection, "Host: $host");
fputs ($connection, "\r\n\r\n");
$headerStart = 0;
$headerEnd = 0;
$redirecting = false;
while (!feof($connection))
{
$currentLine = fgets ($connection, 1024);
if ($headerEnd && $redirecting)
{
break;
}
else if ($headerEnd && !$redirecting)
{
//this is the html from the page
$contents = $contents . $currentLine;
}
else if ( ereg("HTTP", $currentLine) )
{
//came to the start of the header
$headerStart = 1;
}
else if ( $headerStart && ereg("[\n\r\t ]*$",
$currentLine) )
{
//came to the end of the header
$headerEnd = 1;
}
else
{
//this is the header, if you want it...
if (preg_match("/Location: (.+?)\n/is",$currentLine,$matches)
)
{
//redirects are sometimes relative
$newurl = $matches[1];
if (!preg_match("/http:\/\//i", $newurl, $matches) )
{
$url .= $newurl;
}
else
{
$url = $newurl;
}
//extra \r's get picked up sometimes
//i think only with relative redirects
//this is a quick fix.
$url = preg_replace("/\r/s","",$url);
$redirecting = true;
}
}
}
}
else
{
echo "$errstr ($errno)\n";
$url = "";
}
fclose ($connection);
}
print $contents;
?>
Thanks in advance
JM