2010-05-07 145 views
1

我跟着Wordpress autologin using CURL or fsockopen in PHP登錄到wordpress,使用php_curl,它工作得很好,因爲我使用WAMP,(apache/php)。PHP curl post登錄到wordpress

但是,當談到專用服務器上的IIS時,它什麼都不返回。

我寫了下面的函數,它對我的​​本地wamp很好,但是當部署到客戶端的專用windows服務器2k3時,它不會。請幫我

function post_url($url, array $query_string) 
    { 
     //$url = http://myhost.com/wptc/sys/wp/wp-login.php 
     /*  $query_string = array(
          'log'=>'admin', 
          'pwd'=>'test', 
          'redirect_to'=>'http://google.com', 
          'wp-submit'=>'Log%20In', 
          'testcookie'=>1 
         ); 
     */ 

     //temp_dir is defined as folder = path/to/a/folder 
     $cookie= temp_dir."cookie.txt"; 


     $c = curl_init($url); 



     if (count($query_string)) 
     { 
      curl_setopt ($c, CURLOPT_POSTFIELDS, 
       http_build_query($query_string) 
      ); 

     } 

     curl_setopt($c, CURLOPT_POST, 1); 
     curl_setopt($c, CURLOPT_COOKIEFILE, $cookie); 
     //curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 1); 
     //curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
     curl_setopt($c, CURLOPT_TIMEOUT, 60); 
     curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); //return the content 
     curl_setopt($c, CURLOPT_COOKIEJAR, $cookie); 
     //curl_setopt($c, CURLOPT_AUTOREFERER, 1); 
     //curl_setopt($c, CURLOPT_REFERER, wp_admin_url); 
     //curl_setopt($c, CURLOPT_MAXREDIRS, 10); 

     curl_setopt($c, CURLOPT_HEADER, 0); 
     //curl_setopt($c, CURLOPT_CRLF, 1); 


     try { 
      $result = curl_exec($c); 
     } 
     catch (Exception $e) 
     { 
      $result = 'error'; 
     } 

     curl_close ($c); 

     return $result; //it return nothing (empty) 
    } 

其他事實

  1. curl_error($ C);返回任何
  2. 時頭CURLOPT_HEADER設置爲ON, 它返回這個頭

HTTP/1.1 200 OK緩存控制:無緩存, 必重新驗證,最大年齡= 0附註: no-cache Content-Type:text/html; 的charset = UTF-8過期時間:週三,01月11日1984年 GMT 05:00:00的Last-Modified: 星期四,2010 05月06日21時06分三十秒GMT 服務器:Microsoft-IIS/7.0 X供電,通過:PHP/5.2.13 Set-Cookie: wordpress_test_cookie = WP + Cookie + check;路徑=/wptc/sys/wp/Set-Cookie: wordpress_b13661ceb5c3eba8b42d383be885d372 = admin%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b; path =/wptc/sys/wp/wp-content/plugins; httponly Set-Cookie:wordpress_b13661ceb5c3eba8b42d383be885d372 = admin%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b; path =/wptc/sys/wp/wp-admin; httponly Set-Cookie: wordpress_logged_in_b13661ceb5c3eba8b42d383be885d372 = admin%7C1273352790%7Cb90825fb4a7d5da9b5dc4d99b4e06049; path =/wptc/sys/wp /;僅Http 刷新: 0; URL = http://myhost.com/wptc/sys/wp/wp-admin/ X供電-通過:ASP.NET日期:星期四,06 2010年5月21時06分30秒GMT 的Content-Length:0

  • CURL版本信息: Array([version_number] => 463872 [age] => 3 [features] => 2717 [ssl_version_number] => 0 [version] => 7.20.0 [host] => i386- pc-win32 [ssl_version] => OpenSSL/0.9.8k [libz_version] => 1.2.3 [protocols] => Array([0] => dict [1] => file [2] => ftp [3] = > ftps [4] => http [5] => https [6] => imap [7] => imaps [8] => ldap [9] => pop3 [10] => pop3s [11] => rtsp [12] => smtp [13] => smtps [14] => telnet [15] => tftp))

  • PHP版本5.2.13
  • 的Windows Server 2K3
  • IIS 7
  • 在我的本地在Apache,PHP 3.0做工精細(窗口)
  • 回答

    0

    快速思考:檢查以確保temp_dir。「cookie.txt」可由IIS寫入。

    0

    我設法自己修復它,這是在WordPress的一些小的修復,而不是任何IIS或PHP的具體信息。

    我在下面的部分修改wp_redirect()(只是評論主要部分)解決它

    function wp_redirect($location, $status = 302) { 
        global $is_IIS; 
    
        $location = apply_filters('wp_redirect', $location, $status); 
        $status = apply_filters('wp_redirect_status', $status, $location); 
    
        if (!$location) // allows the wp_redirect filter to cancel a redirect 
         return false; 
    
        $location = wp_sanitize_redirect($location); 
    
        /* 
        if ($is_IIS) { 
         status_header($status); 
         header("Refresh: 0;url=$location"); 
        } else { 
         if (php_sapi_name() != 'cgi-fcgi') { 
          status_header($status); // This causes problems on IIS and some FastCGI setups 
    
         } 
         header("Location: $location", true, $status); 
        } 
        */ 
        header("Location: $location", true, $status); 
    }