note 91554 modified in function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Tue, 16 Jun 2009 20:18:55 +0000 |
| Subject: | note 91554 modified in function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156945@lists.php.net to get a copy of this message | ||
look at this smart ssl/http fsockopen function as a good solution for dealing with things
<?php
function _get($type,$host,$port='80',$path='/',$data='') {
$_err = 'lib sockets::'.__FUNCTION__.'(): ';
switch($type) { case 'http': $type = ''; case 'ssl': continue;
default: die($_err.'bad $type'); } if(!ctype_digit($port)) die($_err.'bad
port');
if(!empty($data)) foreach($data AS $k => $v) $str .=
urlencode($k).'='.urlencode($v).'&'; $str = substr($str,0,-1);
$fp = fsockopen($host,$port,$errno,$errstr,$timeout=30);
if(!$fp) die($_err.$errstr.$errno); else {
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($str)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $str."\r\n\r\n");
while(!feof($fp)) $d .= fgets($fp,4096);
fclose($fp);
} return $d;
}
?>
--was--
look at this smart ssl/http fsockopen function as a good solution for dealing with things
[code]function _get($type,$host,$port='80',$path='/',$data='') {
$_err = 'lib sockets::'.__FUNCTION__.'(): ';
switch($type) { case 'http': $type = ''; case 'ssl': continue;
default: die($_err.'bad $type'); } if(!ctype_digit($port)) die($_err.'bad
port');
if(!empty($data)) foreach($data AS $k => $v) $str .=
urlencode($k).'='.urlencode($v).'&'; $str = substr($str,0,-1);
$fp = fsockopen($host,$port,$errno,$errstr,$timeout=30);
if(!$fp) die($_err.$errstr.$errno); else {
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($str)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $str."\r\n\r\n");
while(!feof($fp)) $d .= fgets($fp,4096);
fclose($fp);
} return $d;
}[/code]
http://php.net/manual/en/function.fsockopen.php