php fsockopen imitates user post data_PHP tutorial

WBOY
Release: 2016-07-13 16:55:06
Original
755 people have browsed it

A simple use of PHP related functions to implement data submission, friends in need can refer to it.

The code is as follows
 代码如下 复制代码

function wfopen($url,$post='',$cookie='',$timeout=15) {
$matches = parse_url($url);
$out = "POST {$matches['path']} HTTP/1.0rn";
$out .= "Accept: */*rn";
$out .= "Accept-Language: zh-cnrn";
$out .= "Content-Type: application/x-www-form-urlencodedrn";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT] rn";
$out .= "Host: {$matches['host']}rn";
$out .= 'Content-Length: '.strlen($post)."rn";
$out .= "Connection: Closern";
$out .= "Cache-Control: no-cachern";
$out .= "Cookie: $cookiernrn";
$out .= $post;
$socket = @fsockopen($matches['host'],80,$errno,$errstr,$timeout) or die("$errstr($errno)");
fwrite($socket,$out);
$header = $data = "";
while($infos = trim(fgets($socket,4096))) {
$header.=$infos;
}
while(!feof($socket)) {
$data .= fgets($socket,4096);
}
return $data;
}
echo wfopen('http://localhost/te.php','id=5');
?>

te.php

if(!empty($_POST['id'])) {
echo setcookie('auth','haowei',time()+3600,'/') ? 1 : 0;
}

Copy code
function wfopen($url,$post='',$cookie='',$timeout=15) {
          $matches = parse_url($url);
           $out = "POST {$matches['path']} HTTP/1.0rn";
          $out .= "Accept: */*rn";
$out .= "Accept-Language: zh-cnrn";
$out .= "Content-Type: application/x-www-form-urlencodedrn";
          $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT] rn";
$out .= "Host: {$matches['host']}rn";
$out .= 'Content-Length: '.strlen($post)."rn";
$out .= "Connection: Closern";
          $out .= "Cache-Control: no-cachern";
$out .= "Cookie: $cookiernrn";
          $out .= $post;
$socket = @fsockopen($matches['host'],80,$errno,$errstr,$timeout) or die("$errstr($errno)");
            fwrite($socket,$out);
          $header = $data = "";
​​​​while($infos = trim(fgets($socket,4096))) {
                      $header.=$infos;
         }
​​​​while(!feof($socket)) {
                       $data .= fgets($socket,4096);
         }
         return $data;
}
echo wfopen('http://localhost/te.php','id=5');
?>

te.php

http://www.bkjia.com/PHPjc/631696.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/631696.htmlTechArticleA simple use of PHP related functions to implement data submission. Friends in need can refer to it. The code is as follows Copy the code ?php function wfopen($url,$post='',$cookie='',$timeo...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!