1. Get the Web content get by using PHP
function Socketget ($url, & $ret)
{
$URLARR = Parse_url ($url);
$host = $URLARR [' Host '];
$port = Isset ($urlArr [' Port '])? $URLARR [' Port ']:80;
$path = Isset ($urlArr [' path '])? $URLARR [' Path ']: "/";
$fp = Fsockopen ($host, $port, $errno, $errstr, 30);
if (! $fp)
{
echo "$errstr ($errno)
\ n ";
return false;
}
Else
{
$out = "GET $path http/1.1\r\n";
$out. = "Host: $host \ r \ n";
$out. = "connection:close\r\n\r\n";
$ret = "";
Fwrite ($fp, $out);
while (!feof ($FP))
{
$ret. = Fgets ($fp, 128);
}
Fclose ($FP);
}
return true;
}
?>
2. POST data to the page using PHP
function Socketpost ($url, $data, & $ret)
{
$URLARR = Parse_url ($url);
$host = $URLARR [' Host '];
$port = Isset ($urlArr [' Port '])? $URLARR [' Port ']:80;
$path = Isset ($urlArr [' path '])? $URLARR [' Path ']: "/";
$fp = Fsockopen ($host, $port, $errno, $errstr, 30);
if (! $fp)
{
echo "$errstr ($errno)
\ n ";
return false;
}
Else
{
$out = "POST $path http/1.1\r\n";
$out. = "Host: $host \ r \ n";
$out. = "content-type:application/x-www-form-urlencoded\r\n";
$out. = "Content-length:". strlen ($data). " \ r \ n ";
$out. = "connection:keep-alive\r\n\r\n";
$out. = $data;
$ret = "";
Fwrite ($fp, $out);
while (!feof ($FP))
{
$ret. = Fgets ($fp, 128);
}
Fclose ($FP);
}
return true;
}
?>
If post is an error, turn $out = "connection:keep-alive\r\n\r\n"; keep-alive in to close
Excerpt from The Times
http://www.bkjia.com/PHPjc/478311.html www.bkjia.com true http://www.bkjia.com/PHPjc/478311.html techarticle 1. Get the Web content by using PHP? PHP function Socketget ($url, $ret) {$urlArr = Parse_url ($url); $host = $URLARR [host]; $port = Isset ($URLARR [port])? $URLARR [port]:80; $pa ...