I've been trying to read a page with fsockopen, that page returns a location
header but when parsing the header and trying to read the page
it points to I get a different result than when using my browser...
Does any one have any suggestions how to get the same result as when using a
browser?
I included the function i wrote to get html pages...
and this is the basic structure of my code to read the page...
$page = GetPage("GET blah.com/blah.html");
$newurl = parse the $page for the location header;
$page = GetPage("GET $newurl");
the final result is different as I said than when using my browser... the
site i'm trying to access somehow knows that i'm not using a browser or
something like
that
any ideas at all would be welcome!!
Ali Shahid
function GetPage($url,$fp, $cookies = "", $body = "", $agent = "Mozilla/4.0
(compatible; MSIE 5.0; Windows 98; DigExt)")
{
//parse url
preg_match("/(.*?) (http:\/\/)?(.*?)\/(.*)/", $url, $match);
$method = strtoupper($match[1]);
$host = $match[3];
$uri = $match[4];
echo $fp;
//prepare headers to be sent to server
$p = "$method /$uri HTTP/1.1\r\n";
$p .= "Host: $host\r\n";
$p .= "User-Agent: $agent\r\n";
$p .= "Accept: */*\r\n";
if ($method == "POST") {
$p .= "Content-Type: application/x-www-form-urlencoded\r\n";
$p .= "Content-Length: ".strlen($body)."\r\n";
}
$p .= "Connection: Keep-Alive\r\n";
$p .= "Accept-Encoding: gzip, deflate\r\n";
$p .= "Accept-Language: he\r\n";
$p .= "Authorization: Basic ZG9yb246bG92ZW1l\r\n";
if ($cookies)
$p .= "Cookie: $cookies\r\n";
$p .= "\r\n";
if ($method == "POST")
$p .= $body."\r\n";
//open connection
if(!$fp)
{
echo "opening socket";
$fp = fsockopen("$host", 80, &$errno, &$errstr, 60);
$opened=1;
}
if(!$fp)
echo "Error Opening $host - $errno - $errstr\n<br>";
//start reading page
else
{
//socket_set_timeout($fp, 60);
fputs($fp, $p);
while((!feof($fp)) )
{
$SourcePage .= fgets($fp, 1024);
}
if($opened)
{
echo "closing";
fclose($fp);
}
}
//return the page
return($SourcePage);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]