Home > Backend Development > PHP Tutorial > PHP simulates post submission data_PHP tutorial

PHP simulates post submission data_PHP tutorial

WBOY
Release: 2016-07-21 14:54:10
Original
851 people have browsed it

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)) { // LieHuo5885网>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);
}

Original address: http://www.52blogger.com/archives/595

http://www.bkjia.com/PHPjc/364684.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364684.htmlTechArticlePHP simulates post submission data, which has many uses and can be used for website collection, login, etc.//In my project Forum login as an example function A_bbslogin($user_login,$password,$host,$port=80){ //Required...
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