Heim >Backend-Entwicklung >PHP-Tutorial >php fsockopen模仿用户post数据_PHP教程

php fsockopen模仿用户post数据_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 16:55:06821Durchsuche

一个简单的利用php的相关函数来实现数据提交,有需要的朋友可以参考一下。

 代码如下 复制代码

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;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/631696.htmlTechArticle一个简单的利用php的相关函数来实现数据提交,有需要的朋友可以参考一下。 代码如下 复制代码 ?php function wfopen($url,$post='',$cookie='',$timeo...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn