curl-and-php
PHP-libcurl URL Redirections problem during login
Date: Thu, 6 Apr 2006 12:18:49 -0700 (PDT)
Hi All,
I am having a problem with PHP-libcurl url redirections during login to a website.It takes me back to the welcome page.
The same scenario works well using cURL.
1) My cURL script is as given below: { Working fine }
curl -b Kookie -c Kookie -o step01.html -v -i -k -L -d @authz https://MMM.NNN.YYY.com/welcome.asp
When i run the above cURL script , i get a HTTP/1.1 100 Continue>>>HTTP/1.1 302 Object moved{Here a GET to the Login page is issued} >>>HTTP/1.1 200 OK {Login page}
Please find below the verbose output of the same:
==============================================================================
* About to connect() to AAA.BBB.CCC.com port 443
* Trying 66.192.78.34... connected
* Connected to AAA.BBB.CCC.com (66.192.78.34) port 443
* error setting certificate verify locations, continuing anyway:
* CAfile: /usr/local/share/curl/curl-ca-bundle.crt
CApath: none
* SSLv2, Client hello (1):
SSLv3, TLS handshake, Server hello (2):
SSLv3, TLS handshake, CERT (11):
SSLv3, TLS handshake, Server finished (14):
SSLv3, TLS handshake, Client key exchange (16):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSL connection using RC4-MD5
* Server certificate:
* subject: /C=US/ST=Ohio/L=Cincinnati/O=First Data Corporation./OU=DataCe
nter/CN=AAA.BBB.CCC.com
* start date: 2005-05-25 17:20:34 GMT
* expire date: 2006-08-25 17:20:34 GMT
* common name: AAA.BBB.CCC.com (matched)
* issuer: /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
* SSL certificate verify result: unable to get local issuer certificate (20), co
ntinuing anyway.
> POST /web/AAA/welcome.asp HTTP/1.1
> User-Agent: curl/7.15.3 (i586-pc-mingw32msvc) libcurl/7.15.3 OpenSSL/0.9.7c zl
ib/1.2.2
> Host: AAA.BBB.CCC.com
> Accept: */*
> Cookie: ASPSESSIONIDCADQQSBS=LIDIGPJDBMMBFHIDPDKHCJME; ASPSESSIONIDCQCDTSSD=HN
JHFAABDCKAPGLLKJPNMPHC
> Content-Length: 81
> Content-Type: application/x-www-form-urlencoded
>
> param1=067884¶m2=4559&cmdContinue.x=66&cmdContinue.y
=19HTTP/1.1 100 Continue
< Server: Microsoft-IIS/5.0
< Date: Wed, 05 Apr 2006 21:24:31 GMT
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<
PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T05:
56-0500" exp "2005.06.16T12:00-0500" r (v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< HTTP/1.1 302 Object moved
< Server: Microsoft-IIS/5.0
< Date: Wed, 05 Apr 2006 21:24:31 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T0
5:56-0500" exp "2005.06.16T12:00-0500" r (v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< Location: Login.asp
< Content-Length: 130
< Content-Type: text/html
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0<
Expires: Tue, 04 Apr 2006 21:24:30 GMT
* Added cookie ASPSESSIONIDCASDCSAA="NPGLLLDCDINJNPOLFMGPMLJF" for domain AAA.BBB.CCC.com, path /, expire 0
< Set-Cookie: ASPSESSIONIDCASDCSAA=NPGLLLDCDINJNPOLFMGPMLJF; path=/
< Cache-control: no-cache
* Ignoring the response-body
100 130 100 130 0 0 85 0 0:00:01 0:00:01 --:--:-- 120*
Connection #0 to host AAA.BBB.CCC.com left intact
* Issue another request to this URL: 'https://AAA.BBB.CCC.com/web/AAA/Login.asp'
* Disables POST, goes with GET
* Re-using existing connection! (#0) with host AAA.BBB.CCC.com
* Connected to AAA.BBB.CCC.com (66.192.78.34) port 443
> GET /web/AAA/Login.asp HTTP/1.1
> User-Agent: curl/7.15.3 (i586-pc-mingw32msvc) libcurl/7.15.3 OpenSSL/0.9.7c zl
ib/1.2.2
> Host: AAA.BBB.CCC.com
> Accept: */*
> Cookie: ASPSESSIONIDCASDCSAA=NPGLLLDCDINJNPOLFMGPMLJF; ASPSESSIONIDCADQQSBS=LI
DIGPJDBMMBFHIDPDKHCJME; ASPSESSIONIDCQCDTSSD=HNJHFAABDCKAPGLLKJPNMPHC
>
< HTTP/1.1 200 OK
< Server: Microsoft-IIS/5.0
< Date: Wed, 05 Apr 2006 21:24:32 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T0
5:56-0500" exp "2005.06.16T12:00-0500" r (v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< Content-Length: 5772
< Content-Type: text/html
< Expires: Tue, 04 Apr 2006 21:24:32 GMT
< Cache-control: no-cache
100 5772 100 5772 0 0 3413 0 0:00:01 0:00:01 --:--:-- 3413Co
nnection #0 to host AAA.BBB.CCC.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
==============================================================================
2) My PHP-libcurl script is as given below: { NOT Working - Improper Redirections! }
<?php
echo "** Testing cURL - PHP CLI --IN**\n";
$cookie_file = "C:/MMM/AAA/Kookie";
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322";
$url = "https://MMM.NNN.YYY.com/welcome.asp";
$cafile = "C:/tools/curl-7.15.3/curl-ca-bundle.crt";
$savefile = "C:/MMM/AAA/step01.html";
$errorfile = "verbose_file.txt";
$formData = "param1=067884¶m2=4559&cmdContinue.x=66&cmdContinue.y=19";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch , CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_CAINFO,$cafile );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formData );
curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
//curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$fp = fopen ($savefile, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec ($ch);
if (curl_errno($ch)) print curl_error($ch);
$fp_err = fopen($errorfile, 'ab+');
fwrite($fp_err, date('Y-m-d H:i:s')."\n\n");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_STDERR, $fp_err);
fclose ($fp);
curl_close ($ch);
echo "** Testing using cURL - PHP CLI --OUT**";
?>
i) When i run the above php script with options as
a)FollowLocation option set to 1
b)without MaxRedirs option
c)tried cookie handling also
i get a HTTP/1.1 100 Continue>>>HTTP/1.1 302 Object moved{Here a GET to the Login page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the default page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the welcome page is issued} >>>
HTTP/1.1 200 OK {welcome page}
Please find below the verbose output of the same:
==================================================================================
** Testing using cURL - PHP CLI --IN**
* About to connect() to AAA.BBB.CCC.com port 443
* Trying 66.192.78.34... * connected
* Connected to AAA.BBB.CCC.com (66.192.78.34) port 443
* successfully set certificate verify locations:
* CAfile: C:/tools/curl-7.15.3/curl-ca-bundle.crt
CApath: none
* SSL connection using RC4-MD5
* Server certificate:
* subject: /C=US/ST=Ohio/L=Cincinnati/O=First Data Corporation./OU=DataCenter/CN=AAA.BBB.CCC.com
* start date: 2005-05-25 17:20:34 GMT
* expire date: 2006-08-25 17:20:34 GMT
* common name: AAA.BBB.CCC.com (matched)
* issuer: /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
* SSL certificate verify ok.
> POST /web/AAA/welcome.asp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322
Host: AAA.BBB.CCC.com
Accept: */*
Content-Length: 81
Content-Type: application/x-www-form-urlencoded
param1=067884¶m2=4559&cmdContinue.x=66&cmdContinue.y
=19HTTP/1.1 100 Continue
< Server: Microsoft-IIS/5.0
< Date: Thu, 06 Apr 2006 00:32:08 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T05:56-0500" exp "2005.06.16T12:00-0500" r
(v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< HTTP/1.1 302 Object moved
< Server: Microsoft-IIS/5.0
< Date: Thu, 06 Apr 2006 00:32:09 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T05:56-0500" exp "2005.06.16T12:00-0500" r
(v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< Location: Login.asp
< Content-Length: 130
< Content-Type: text/html
< Expires: Wed, 05 Apr 2006 00:32:08 GMT
< Set-Cookie: ASPSESSIONIDCASDCSAA=FAILLLDCJLKMMHMFBAHEJHPG; path=/
< Cache-control: no-cache
* Ignoring the response-body
* Connection #0 to host AAA.BBB.CCC.com left intact
* Issue another request to this URL: 'https://AAA.BBB.CCC.com/web/AAA/Login.asp'
* Disables POST, goes with GET
* Re-using existing connection! (#0) with host AAA.BBB.CCC.com
* Connected to AAA.BBB.CCC.com (66.192.78.34) port 443
> GET /web/ALO_AAA/Login.asp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322
Host: AAA.BBB.CCC.com
Accept: */*
< HTTP/1.1 302 Object moved
< Server: Microsoft-IIS/5.0
< Date: Thu, 06 Apr 2006 00:32:09 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T05:56-0500" exp "2005.06.16T12:00-0500" r
(v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< Location: ../default.asp
< Content-Length: 135
< Content-Type: text/html
< Expires: Wed, 05 Apr 2006 00:32:10 GMT
< Set-Cookie: ASPSESSIONIDCASDCSAA=GAILLLDCKCPIADPMGGEAEOLF; path=/
< Cache-control: no-cache
* Ignoring the response-body
* Connection #0 to host AAA.BBB.CCC.com left intact
* Issue another request to this URL: 'https://AAA.BBB.CCC.com/web/default.asp'
* Re-using existing connection! (#0) with host AAA.BBB.CCC.com
* Connected to AAA.BBB.CCC.com (66.192.78.34) port 443
> GET /web/default.asp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322
Host: AAA.BBB.CCC.com
Accept: */*
< HTTP/1.1 302 Object moved
< Server: Microsoft-IIS/5.0
< Date: Thu, 06 Apr 2006 00:32:09 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T05:56-0500" exp "2005.06.16T12:00-0500" r
(v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< Location: ./AAA/welcome.asp
< Content-Length: 142
< Content-Type: text/html
< Expires: Wed, 05 Apr 2006 00:32:10 GMT
< Set-Cookie: ASPSESSIONIDCASDCSAA=HAILLLDCCFJJHLFCEGOEDKFH; path=/
< Cache-control: no-cache
* Ignoring the response-body
* Connection #0 to host AAA.BBB.CCC.com left intact
* Issue another request to this URL: 'https://AAA.BBB.CCC.com/web/ALO_AAA/welcome.asp'
* Re-using existing connection! (#0) with host AAA.BBB.CCC.com
* Connected to AAA.BBB.CCC.com (66.192.78.34) port 443
> GET /web/welcome.asp HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322
Host: AAA.BBB.CCC.com
Accept: */*
< HTTP/1.1 200 OK
< Server: Microsoft-IIS/5.0
< Date: Thu, 06 Apr 2006 00:32:11 GMT
< PICS-Label: (PICS-1.0 "http://www.rsac.org/ratingsv01.html" l on "2004.06.16T05:56-0500" exp "2005.06.16T12:00-0500" r
(v 0 s 0 n 0 l 0))
< X-Powered-By: ASP.NET
< Content-Length: 10224
< Content-Type: text/html
< Expires: Wed, 05 Apr 2006 00:32:10 GMT
< Set-Cookie: ASPSESSIONIDCASDCSAA=IAILLLDCFOKJNABBBLAJFINJ; path=/
< Cache-control: no-cache
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Curl_xxx_rcvs returned -1, block = TRUE
* Connection #0 to host AAA.BBB.CCC.com left intact
** Testing using cURL - PHP CLI --OUT**
ii)When i run the above php script with options as
a)FollowLocation option set to 1
b)without MaxRedirs 1 option
c)tried cookie handling also
i get a HTTP/1.1 100 Continue>>>HTTP/1.1 302 Object moved{Here a GET to the Login page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the default page is issued}
iii)When i run the above php script with options as
a)FollowLocation option set to 1
b)without MaxRedirs 2 option
c)tried cookie handling also
i get a HTTP/1.1 100 Continue>>>HTTP/1.1 302 Object moved{Here a GET to the Login page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the default page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the welcome page is issued}
iv) When i run the above php script with options as
a)FollowLocation option set to 0
b)tried cookie handling also
i get a HTTP/1.1 100 Continue>>>HTTP/1.1 302 Object moved{Here a GET to the Login page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the default page is issued} >>>
HTTP/1.1 302 Object moved{Here a GET to the welcome page is issued} {same as case iii}
Please help in suggesting a solution for this libcurl - php login problem.
Any help will be appreciated,
Thanks much,
Priya
---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-04-06