PHP curl post登录到wordpress

PHP curl post登录到wordpress,php,curl,Php,Curl,我随后使用php_curl登录到wordpress,就我使用WAMP(apache/php)而言,它工作得很好 但是,当涉及到专用服务器上的IIS时,它什么也不返回 我已经编写了以下函数,该函数在我的本地wamp上运行良好,但当部署到客户端的专用windows服务器2k3时,它就不工作了。请帮帮我 function post_url($url, array $query_string) { //$url = http://myhost.com/wptc/sys/wp/wp

我随后使用php_curl登录到wordpress,就我使用WAMP(apache/php)而言,它工作得很好

但是,当涉及到专用服务器上的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)
    }
其他事实
  • 旋度误差($c);一无所获
  • 当header CURLOPT_header设置为ON时, 它返回这个标题
  • HTTP/1.1200 确定缓存控制:无缓存, 必须重新验证,最大年龄=0 Pragma: 无缓存内容类型:text/html; 字符集=UTF-8到期日期:1月11日星期三 1984 05:00:00 GMT上次修改时间: 2010年5月6日星期四格林威治时间21:06:30 服务器:Microsoft IIS/7.0 X-Powered-By:PHP/5.2.13设置Cookie: wordpress\u test\u cookie=WP+cookie+check; 路径=/wptc/sys/wp/Set Cookie: wordpress_b13661ceb5c3eba8b42d383be885d372=管理员%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b; path=/wptc/sys/wp/wp content/plugins; httponly Set Cookie:wordpress_b13661ceb5c3eba8b42d383be885d372=管理员%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b; 路径=/wptc/sys/wp/wp admin;httponly 设置Cookie: wordpress(已登录)b13661ceb5c3eba8b42d383be885d372=管理员%7C1273352790%7Cb90825fb4a7d5da9b5dc4d99b4e06049; 路径=/wptc/sys/wp/;httponly 刷新: 0;网址= X-Powered-By:ASP.NET日期:2006年4月4日 2010年5月21:06:30格林尼治标准时间 内容长度:0

  • 卷曲版本信息: 阵列([版本号]=>463872[年龄]=>3[功能]=>2717[ssl版本号]=>0[版本]=>7.20.0[主机]=>i386-pc-win32[ssl版本]=>OpenSSL/0.9.8k[自由版本]=>1.2.3[协议]=>阵列([0]=>dict[1]=>file[2]=>ftp[3]=>ftps[4]=>http[5]=>https[6]=>imap[7]=>pop3][11] =>rtsp[12]=>smtp[13]=>smtps[14]=>telnet[15]=>tftp)

  • PHP版本5.2.13
  • Windows服务器2K3
  • IIS 7
  • 在我的本地主机(windows)上的Apache和PHP3.0上运行良好

  • 快速思考:检查以确保temp_dir.“cookie.txt”可由IIS写入。

    我自己设法修复了它,这是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);
    }