Hi,
I try to make some kind od HTTP tunnel in PHP. Shortly:
1.) I connect to port 80 of HTTP server
2.) I send GET/POST request
3.) I receive output (including headers) and save it to file
In this case I tried to read "fuzzy.zip" file from remote server (in this case local but it doesn't matter) and write it to "out.txt" on my server and then to send HTTP headers, read "out.txt" from my server and send it to browser.
instead: SERVER <-> BROWSER
i try to do: SERVER <-> MY SERVER <-> BROWSER
Here is a code I use for that:
=====================CUT==================
<?
$pic="/6/fuzzy.zip";
$str="GET ".$pic." HTTP/1.1
Accept: /
Accept-Language: cs-cz
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: localhost
Connection: Keep-Alive
";
$fp = fsockopen ("localhost", 80);
fputs ($fp, $str);
while (!feof($fp))
{
$data.=fgets ($fp,128);
}
fclose ($fp);
$fr= fopen ("out.txt","w+");
fputs ($fr,$data);
?>
=====================CUT==================
Then I try to reproduce that page/file by feeding IE with data from that file (after cutting headers):
=====================CUT==================
<?
$fd = fopen ("out.txt", "rb");
while (!feof ($fd)) {
$buffer = $buffer.fgets($fd, 128);
}
fclose ($fd);
Header ("Date: Thu, 12 Sep 2002 08:46:19 GMT
Server: Apache/2.0.28 (Win32)
Last-Modified: Thu, 18 Apr 2002 13:31:48 GMT
ETag: \"0-6427-41753900\"
Accept-Ranges: bytes
Content-Length: 25639
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: application/zip
");
echo $buffer;
?>
=====================CUT==================
the result should be that the same file should be offered for download, in fact I always get wrong file. It starts with PKZIP header but it's shorter and different. Nor did I with images and so. That PHP script should be transparent.
I stole the header from some monitoring software (I wanted to know what headers browser is sending)
So, what am I doing wrong ? Why I am not able to get the correct file ?
Thanx in advance. This is not supposed to be so hard but I can't find that damn mistake...