PHP uses socket to simulate post fsockopen to send data_PHP tutorial

WBOY
Release: 2016-07-20 11:10:24
Original
854 people have browsed it

I'm a little upset today. Let's write an article about php fsockopen post related data. We can imitate the source and then send it to the other server. Friends in need can take a look.

Pragma: no-cacheCache-Control: no-cache
The code is as follows
 代码如下 复制代码

POST /目的程序 HTTP/1.1
Accept: */*
Referer: http://www.hzhuti.com
Accept-Language: zh-cn,en-us;q=0.5
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
Host: 要发送到的主机地址
Content-Length: 发送数据的长度
Pragma: no-cache
Cache-Control: no-cache
username=php&password=iask   //post发送的数据

Copy code


POST /destination program HTTP/1.1

Accept: */*
Referer: http://www.hzhuti.com
Accept-Language: zh-cn,en-us;q= 0.5
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; .NET CLR 1.0.3705; .NET CLR 1.1.4322)

Host: The host address to be sent to
 代码如下 复制代码

$port = $url['port'] ? $url['port'] : 80;
$fp = fsockopen($url['host'], $port, $errno, $errstr,10);
if (!$fp) return "在主机: $url[host] $port 打开socket失败,失败原因是: $errno - $errstr";
fputs($fp, sprintf("POST %s%s%s HTTP/1.0rn", $url['path'], $url['query'] ? "?" : "", $url['query']));
fputs($fp, "Host:".$url['host']."rn");
fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
fputs($fp, "Content-length: " . strlen($encoded) . "rn");
fputs($fp, "Connection: closernrn");
fputs($fp, "$encodedn");

Content-Length: The length of the sent data
username=php&password=iask // Data sent by post

fsockopen (host name, port number, error number acceptance variable, error prompt acceptance variable, timeout) The host name is the destination you need to send data to; The port number is the port on which the destination program will wait for your data; The error number accepts the variable, which is returned if the socket establishment is unsuccessful. The error number; error prompt variable is the error prompt message returned when an error occurs; timeout is the longest time to wait if the other party does not respond after posting the data.
The code is as follows Copy code
$port = $url['port'] ? $url['port'] : 80; $fp = fsockopen($url['host'], $port, $errno, $errstr,10); if (!$fp) return "Failed to open socket on host: $url[host] $port. The reason for failure is: $errno - $errstr";
fputs($fp, sprintf("POST %s%s%s HTTP/1.0rn", $url['path'], $url['query'] ? "?" : "", $url['query']));
fputs($fp, "Host:".$url['host']."rn"); fputs($fp, "Content-type: application/x-www-form-urlencodedrn"); fputs($fp, "Content-length: " . strlen($encoded) . "rn"); fputs($fp, "Connection: closernrn"); fputs($fp, " $encodedn"); http://www.bkjia.com/PHPjc/444733.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444733.htmlTechArticleI’m a little upset today, let’s write an article about php fsockopen post related data, we can imitate from Then send it to the other party's server. Friends in need can take a look. ...
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!