note 22335 added to function.fopen
| From: | brandon at louish dot net | Date: | Thu, 13 Jun 2002 23:53:56 +0000 |
| Subject: | note 22335 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31844@lists.php.net to get a copy of this message | ||
Here is an encompassing solution for most requirements. Not tested with SSL:
function WebGet ( $address, $port = 80, $url = '/', $post = false, $cookie = false) {
/* Use fsockopen to catch the URL */
$fp = fsockopen ( $address, $port);
/* Zero Fill */
$ret = '';
if ($fp) {
/* Success. Now check to see the type of request */
if ($post) {
$request = "POST $url HTTP/1.1\n";
$request .= "Host: $address\n";
$request .= "Content-Length: " . strlen( $post ). "\n";
$request .= "Content-Type: application/x-www-form-urlencoded\n";
if ($cookie) $request .= "Cookie: $cookie\n";
$request .= "Connection: Close\n\n";
$request .= $post;
} else {
$request = "GET $url HTTP/1.1\n";
$request .= "Host: $address\n";
$request .= "Content-Type: text/html\n";
if ($cookie) $request .= "Cookie: $cookie\n";
$request .= "Connection: Close\n\n";
}
$return = '';
/* Write the Request */
fputs ($fp, $request);
/* Get the response */
while (!feof($fp)) $ret .= fgets ( $fp, 128 );
/* close the connection */
fclose ($fp);
}
return $ret;
}
--
http://www.php.net/manual/en/function.fopen.php
http://master.php.net/manage/user-notes.php?action=edit+22335
http://master.php.net/manage/user-notes.php?action=delete+22335
http://master.php.net/manage/user-notes.php?action=reject+22335