Home >Backend Development >PHP Tutorial >How to simulate post submission data in php_PHP tutorial

How to simulate post submission data in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:06:47851browse

How to simulate post submission data in php

This article mainly introduces the method of php simulating post submission data. The example analyzes the socket method to simulate post submission data, which has certain For reference value, friends in need can refer to it

The example in this article describes the method of php simulating post submission data. Share it with everyone for your reference. The details are as follows:

PHP simulates post submission data, which has many uses. It can be used for website collection, login, etc.

Here is an example of forum login in my project:

The code is as follows:

function A_bbslogin($user_login,$password,$host,$port="80"){
//Post data that needs to be submitted
$argv = array(
'cookie' => array('user_login' =>$user_login, 'password' => $password,'_wp_http_referer'=>'/bbpress/','re'=>'','remember' =>true)
);
foreach($argv['cookie'] as $key => $value) {
$params[] = $key . '=' . $value;
}
$params = implode('&', $params);
$header = "POST /bbpress/bb-login.php HTTP/1.1rn";
$header .= "Host:$host:$portrn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($params) . "rn";
$header .= "Connection: Closernrn";
$header .= $params;
$fp = fsockopen($host, $port);
fputs($fp, $header);
while(!feof($fp)) {
$str = fgets($fp); //The following is my own logic code, which mainly simulates cookies and can be used to log in synchronously
if(!(strpos($str,"Set-Cookie:") === false)){
$tmparray = explode(" ",$str);
$cookiearray = explode("=",$tmparray[1]);
$cookiepaths = explode("=",$tmparray[6]);
$cookiename = urldecode($cookiearray[0]);
$cookievalue = urldecode(substr($cookiearray[1],0,strlen($cookiearray[1])-1));
$cookietime = time()+3600*24*7;
$cookiepath = urldecode(substr($cookiepaths[1],0,strlen($cookiepaths[1])-1));
setcookie($cookiename,$cookievalue,$cookietime,$cookiepath);
}
}
fclose($fp);
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/957538.htmlTechArticleHow to submit data by php simulated post. This article mainly introduces the method of php simulated post submitting data, and analyzed with examples. The socket method simulates the technique of post submission data, which has certain reference value...
Statement:
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