Newsgroup: it.comp.www.php
Titolo: cURL on IIS

I have wrote the folowing 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
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_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)
	}
Other Facts
===========
) curl_error($c); return nothing
) when header CURLOPT_HEADER is set to ON, it return this header
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
) CURL version info:
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 Version 5.2.13
) Windows Server 2K3
) IIS 7
) Working fine on Apache, PHP 3.0 on my localhost (windows)
) What I thought is CURLOPT_FOLLOWLOCATION is not working on remote
machine
regards,
Sadi

 me you its urgent for a client to meet the deadline
1 - this is an italian  group
2 - "not work" means nothing, what's happen?
you have an error?
what error?

machine
Good hypothesis; but were it true, you'd receive a Location header,
and you aren't even expecting one at this stage.
Which means that the request is somehow in error.
I suspect that the server isn't authenticating the client - and the
failure to correctly store cookies might explain it.
Leonardo
-- 
Los pellegris perjurs, fraiditz,
Qi nos an sai en camp geqitz,
Qi los manten e cortz es tortz,
Que chascuns val mens vius que mortz.



Thank you Leaonardo, for you detailed reply, I carefully applied every
thing and here are the some more facts,
-  || die('curl error @' . (++$stage)), for curl_setopt is not dying
at any stage
- php 3.0 with IIS (5/6/7) is not working either,
- there is  a clear difference b/w the header returned by apache/iis
versions for the same code above,
This is returned for apache when curl_setopt($c, CURLOPT_HEADER, 1)
is set
HTTP/1.1 302 Found Date: Wed, 12 May 2010 20:02:54 GMT Server: Apache/
2.2.11 (Win32) PHP/5.3.0 X-Powered-By: PHP/5.3.0 Expires: Wed, 11 Jan
1984 05:00:00 GMT Last-Modified: Wed, 12 May 2010 20:02:54 GMT Cache-
Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Set-
Cookie: wordpress_test_cookie=WP+Cookie+check; path=/wptc/sys/wp/ Set-
Cookie: wordpress_8bbca1e8ccaf7a8ccc3ee726cced1aab=admin
%7C1273867374%7C90270340e78812101a24a71b0fc8a509; path=/wptc/sys/wp/wp-
content/plugins; httponly Set-Cookie:
wordpress_8bbca1e8ccaf7a8ccc3ee726cced1aab=admin
%7C1273867374%7C90270340e78812101a24a71b0fc8a509; path=/wptc/sys/wp/wp-
admin; httponly Set-Cookie:
wordpress_logged_in_8bbca1e8ccaf7a8ccc3ee726cced1aab=admin
%7C1273867374%7C7e92652178010344eea643fe6e04dc61; path=/wptc/sys/wp/;
httponly Location: 
http://localhost:8888/wptc/sys/wp/?preview=1&template=classic&stylesheet=classic&TB_iframe=false
Content-Length: 0 Content-Type: text/html; charset=UTF-8 HTTP/1.1 200
OK Date: Wed, 12 May 2010 20:02:54 GMT Server: Apache/2.2.11 (Win32)
PHP/5.3.0 X-Powered-By: PHP/5.3.0 X-Pingback: 
http://localhost:8080/wptc/sys/wp/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT Last-Modified: Wed, 12 May 2010
20:02:54 GMT Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache Content-Length: 5129 Content-Type: text/html;
charset=UTF-8 ...[the content]
and the IIS header
HTTP/1.1 100 Continue Server: Microsoft-IIS/5.1 Date: Wed, 12 May 2010
20:06:19 GMT HTTP/1.1 200 OK Server: Microsoft-IIS/5.1 Date: Wed, 12
May 2010 20:06:19 GMT X-Powered-By: PHP/5.3.2 Expires: Wed, 11 Jan
1984 05:00:00 GMT Last-Modified: Wed, 12 May 2010 20:06:19 GMT Cache-
Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Content-
Type: text/html; charset=UTF-8 Set-Cookie: wordpress_test_cookie=WP
+Cookie+check; path=/wptc/sys/wp/ Set-Cookie:
wordpress_8bbca1e8ccaf7a8ccc3ee726cced1aab=admin
%7C1273867579%7Ca157f0ca1af6b8412db2378cac18141c; path=/wptc/sys/wp/wp-
content/plugins; httponly Set-Cookie:
wordpress_8bbca1e8ccaf7a8ccc3ee726cced1aab=admin
%7C1273867579%7Ca157f0ca1af6b8412db2378cac18141c; path=/wptc/sys/wp/wp-
admin; httponly Set-Cookie:
wordpress_logged_in_8bbca1e8ccaf7a8ccc3ee726cced1aab=admin
%7C1273867579%7C17801b677b47d1819d8bf46f65615dc1; path=/wptc/sys/wp/;
httponly Refresh: 0;url=
http://localhost:8080/wptc/sys/wp/
?
preview=1&template=classic&stylesheet=classic&TB_iframe=false Content-
Length: 0
we can clearly see the header returned, I will surely appreciate you
helping me with that, once solved, i could give $10 via paypal,
regards,
Sadi

helping me with that, once solved, i could give $10 via paypal
Thanks, but that is not necessary. I might need some help myself, someday,
and I'd like to have some debtors come that day :-D
