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.
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.
http://www.bkjia.com/PHPjc/957538.htmlwww.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...