首页  >  文章  >  后端开发  >  php模拟post提交数据_PHP教程

php模拟post提交数据_PHP教程

WBOY
WBOY原创
2016-07-21 14:54:10833浏览

php模拟post提交数据,用处很多,可用来网站的采集,登陆等等

//以我项目中的论坛登录为例
function A_bbslogin($user_login,$password,$host,$port="80"){
//需要提交的post数据
$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.1\r\n";
$header .= "Host:$host:$port\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($params) . "\r\n";
$header .= "Connection: Close\r\n\r\n";
$header .= $params;
$fp = fsockopen($host, $port);
fputs($fp, $header);
while(!feof($fp)) { //  烈5885网(LieHuo29.Net)教76
$str = fgets($fp); //以下是自己的逻辑代码,这里主要是模拟cookie,可用来同步登陆
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);
}

原文地址:http://www.52blogger.com/archives/595

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/364684.htmlTechArticlephp模拟post提交数据,用处很多,可用来网站的采集,登陆等等 //以我项目中的论坛登录为例 function A_bbslogin($user_login,$password,$host,$port=80){ //需要...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn