程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php模擬post提交數據

php模擬post提交數據

編輯:關於PHP編程

       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.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); //以下是自己的邏輯代碼,這裡主要是模擬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);

      }

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved