Home >Backend Development >PHP Tutorial >PHP simulates post submission data_PHP tutorial
PHP simulates post submission data, which has many uses. It can be used for website collection, login, etc.
//Take the forum login in my project as an example
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)) { // LieHuo58火85网>29.Net) Teaching76Process$str = fgets($fp); //The following is my own logic code. It 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);
}