PHP模擬post提交數(shù)據(jù)的函數(shù)代碼

2010-09-10 09:56:52來(lái)源:作者:


PHP Code復(fù)制內(nèi)容到剪貼板


    function A_bbslogin($user_login,$password,$host,$port="80"){   
    //需要提交的post數(shù)據(jù)   
    $argv = array(   
    'cookie' => array('user_login' =>$user_login,

PHP Code復(fù)制內(nèi)容到剪貼板
  1. function A_bbslogin($user_login,$password,$host,$port="80"){   
  2. //需要提交的post數(shù)據(jù)   
  3. $argv = array(   
  4. 'cookie' => array('user_login' =>$user_login'password' => $password,'_wp_http_referer'=>'/bbpress/','re'=>'','remember'=>true)   
  5. );   
  6. foreach($argv['cookie'as $key => $value) {   
  7. $params[] = $key . '=' . $value;   
  8. }   
  9. $params = implode('&'$params);   
  10. $header = "POST /bbpress/bb-login.php HTTP/1.1\r\n";   
  11. $header .= "Host:$host:$port\r\n";   
  12. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";   
  13. $header .= "Content-Length: " . strlen($params) . "\r\n";   
  14. $header .= "Connection: Close\r\n\r\n";   
  15. $header .= $params;   
  16. $fp = fsockopen($host$port);   
  17. fputs($fp$header);   
  18. while(!feof($fp)) {   
  19. $str = fgets($fp); //以下是自己的邏輯代碼,這里主要是模擬cookie,可用來(lái)同步登陸   
  20. if(!(strpos($str,"Set-Cookie:") === false)){   
  21. $tmparray = explode(" ",$str);   
  22. $cookiearray = explode("=",$tmparray[1]);   
  23. $cookiepaths = explode("=",$tmparray[6]);   
  24. $cookiename = urldecode($cookiearray[0]);   
  25. $cookievalue = urldecode(substr($cookiearray[1],0,strlen($cookiearray[1])-1));   
  26. $cookietime = time()+3600*24*7;   
  27. $cookiepath = urldecode(substr($cookiepaths[1],0,strlen($cookiepaths[1])-1));   
  28. setcookie($cookiename,$cookievalue,$cookietime,$cookiepath);   
  29. }   
  30. }   
  31. fclose($fp);   
  32. }  

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

關(guān)鍵詞:PHP

贊助商鏈接: