《PHP教程:php模拟post提交数据的方法》要点:
本文介绍了PHP教程:php模拟post提交数据的方法,希望对您有用。如果有疑问,可以联系我们。
PHP教程本文实例讲述了php模拟post提交数据的办法.分享给大家供大家参考.具体如下:
PHP教程php模拟post提交数据,用处很多,可用来网站的采集,登陆等等
PHP教程这里以我项目中的论坛登录为例加以说明:
代码如下:
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)) {
$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);
}
PHP教程希望本文所述对大家的php程序设计有所赞助.
维易PHP培训学院每天发布《PHP教程:php模拟post提交数据的方法》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。
转载请注明本页网址:
http://www.vephp.com/jiaocheng/12242.html