Home  >  Article  >  Backend Development  >  PHP simulates the method of post submission data, PHP simulates post submission_PHP tutorial

PHP simulates the method of post submission data, PHP simulates post submission_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:07:05646browse

php simulates post submission method, php simulates post submission

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:

Copy code 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/957117.htmlTechArticlephp simulates the method of post submission data, php simulates post submission. The example of this article describes the method of php simulates post submission data. Share it with everyone for your reference. The details are as follows: php simulates post submission...
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