Page 1 of 1

cURL on IIS, problem handling redirect header

Posted: Thu May 06, 2010 4:22 pm
by geniussadi
I have wrote the following function which is working fine on my local wamp, but not when deployed to dedicated windows server 2k3, Please help me you its urgent for a client to meet the deadline

Code: Select all

function post_url($url, array $query_string)
	{
		error_reporting(E_ALL);
		//$url = http://myhost.com/wptc/sys/wp/wp-login.php
		/*$query_string = array(
							'log'=>'admin',
							'pwd'=>'test'
						);
		*/
		
		//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_[b]FOLLOWLOCATION[/b], 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)
	}
Other Facts
===========
)

Code: Select all

curl_error($c);
return nothing
) when header CURLOPT_HEADER is set to ON, it return this header
[text]HTTP/1.1 200 OK Cache-Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Content-Type: text/html; charset=UTF-8 Expires: Wed, 11 Jan 1984 05:00:00 GMT Last-Modified: Thu, 06 May 2010 21:06:30 GMT Server: Microsoft-IIS/7.0 X-Powered-By: PHP/5.2.13 Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/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/; httponly Refresh: 0;url=http://myhost.com/wptc/sys/wp/wp-admin/ X-Powered-By: ASP.NET Date: Thu, 06 May 2010 21:06:30 GMT Content-Length: 0 [/text]


) CURL version info:
[text]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 ) )[/text]

) PHP Version 5.2.13
) Windows Server 2K3
) IIS 7
) Working fine on Apache, PHP 3.0 on my localhost (windows)

Re: cURL on IIS, problem handling redirect header

Posted: Sat May 15, 2010 6:38 am
by geniussadi
I was managed to fix it myself, it was some small fix in the wordpress rather than any IIS or PHP specific information.

I have modified wp_redirect() (just commented major part) in the following part to fix it

Code: Select all

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);
}