Home > Article > Backend Development > php fsockopen fake post and get methods_PHP tutorial
This article provides you with a PHP tutorial for fsockopen to fake post and get methods. If you are looking for PHP processing code for fake post and get methods, this one is good.
//fsocket simulates post submission
$purl = "http://localhost/netphp/test2.php?uu=rrrrrrrrrr";
print_r(parse_url( $url));
sock_post($purl,"uu=55555555555555555");
//fsocket simulates get submission
function sock_get($url, $query)
{
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
$head = "GET ".$info[ 'path']."?".$info["query"]." HTTP/1.0rn";
$head .= "Host: ".$info['host']."rn";
$head .= "rn";
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fread($fp ,4096);
echo $line;
}
}
sock_post($purl,"uu=rrrrrrrrrrrrrr");
function sock_post($url, $query)
{
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
$head = "POST ".$info['path']."?".$info["query"]." HTTP/1.0rn";
$head .= "Host: ".$info['host']." rn";
$head .= "Referer: http://".$info['host'].$info['path']."rn";
$head .= "Content-type : application/x-www-form-urlencodedrn";
$head .= "Content-Length: ".strlen(trim($query))."rn";
$head .= "rn";
$head .= trim($query);
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fread($fp,4096);
echo $line;
}
}
?>