PDA

View Full Version : Opening socket to a file



techno_race
09-20-2008, 09:56 PM
Any ideas how to manipulate the following code...

set_time_limit(20);
ob_start();
header("Content-Type: text/plain");

$host = "www.google.com";

$post = "HEAD / http/1.1\r\n";
$post .= "Host: " . $host . "\r\n";
$post .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2\r\n";
$post .= "Keep-Alive: 200\r\n";
$post .= "Connection: keep-alive\r\n\r\n";

$sock = fsockopen($host,80);
fwrite($sock, $post, strlen($post));

while (!feof($sock)){
echo fgets($sock);
}
ob_end_flush();

Twey
09-20-2008, 10:58 PM
'Manipulate it'? What exactly do you want it to do?

techno_race
09-20-2008, 11:06 PM
... whoops.

I thought I typed:

"... to use a file, rather than a root domain?

Example:

http://www.google.com/program.exe

instead of:

http://www.google.com"

Stupid Internet. :p

Twey
09-21-2008, 01:54 AM
The slash after 'HEAD ' is the path: the section of the URL between the domain and the first #. In your example, you'd change it to '/program.exe'.

HTTP is defined in RFC2616 (ftp://ftp.isi.edu/in-notes/rfc2616.txt). It will be worth a read if you're manipulating HTTP data.