How to open a socket and send headers in php

Tagged:  

I didn't play much with sockets and headers in php, but this is a good place to start.

I got this code from an article about php security:

 

"Of course, you can write your own client instead of manually entering requests with telnet. The following example shows how to perform the same request using PHP:

 

<?php

$http_response = '';

$fp = fsockopen('www.php.net', 80);
fputs($fp, "GET / HTTP/1.1\r\n");
fputs($fp, "Host: www.php.net\r\n\r\n");

while (!feof($fp))
{
$http_response .= fgets($fp, 128);
}

fclose($fp);

echo nl2br(htmlentities($http_response));

?>

Sending your own HTTP requests gives you complete flexibility, and this demonstrates why server-side data filtering is so essential. Without it, you have no assurances about any data that originates from any external source."

 

Pretty cool.