cURL & cookies

From: Date: Sat, 22 Apr 2006 08:12:34 +0000
Subject: cURL & cookies
Groups: php.general 
Request: Send a blank email to php-general+get-234548@lists.php.net to get a copy of this message
Hi, I'm trying to produce an sms sending script, however having problems with curl and storing cookies. The login page works fine, however the second http request returns a login page rather than authenticated content. Additionally, in the headers a different cookie value for JSESSIONID is set. I'm running PHP/5.1.2 on FreeBSD This script: define('COOKIEJAR','/path/to/curl-cookiejar'); define('USERAGENT','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT); curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/cocoon/nonav/secureLogin/login.xml"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array2urlstring($logindata)); curl_setopt($ch, CURLOPT_NOBODY, 1); $return['login'] = curl_exec($ch); curl_close($ch); unset($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/cocoon/websms/websms.xml"); $return['sms'] = curl_exec($ch); curl_close($ch); unset($ch); $fp = fopen(COOKIEJAR,'w'); fclose($fp); echo "<h1>Login</h1>\n"; echo "<pre>\n"; echo htmlspecialchars($return['login']); echo "</pre>\n"; echo "<h1>SMS</h1>\n"; echo "<pre>\n"; echo $return['sms']; echo "</pre>\n"; Produces the output: Login HTTP/1.0 200 OK Date: Sat, 22 Apr 2006 08:04:03 GMT Server: Apache/1.3.33 (Unix) mod_jk/1.2.15 mod_perl/1.29 mod_ssl/2.8.22 OpenSSL/0.9.7e Set-Cookie: JSESSIONID=FC9D098E63E5A065AC8934B7F7BB605A.zooapp02b; Path=/cocoon; Secure Set-Cookie: user=; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ X-Cocoon-Version: 2.1.5.1 Connection: close Content-Type: text/html SMS HTTP/1.1 200 OK Transfer-Encoding: chunked Date: Sat, 22 Apr 2006 08:04:03 GMT Content-Type: text/html Connection: close Set-Cookie: AlteonP=c3b503cb52f50428; path=/ Server: Apache/1.3.33 (Unix) mod_jk/1.2.15 mod_perl/1.29 mod_ssl/2.8.22 OpenSSL/0.9.7e Set-Cookie: JSESSIONID=56D23CCA63E2DDE37293FB64647027D8.zooapp01b; Path=/cocoon Set-Cookie: user=; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ X-Cocoon-Version: 2.1.5.1 Via: 1.1 nsw-cache1 (NetCache NetApp/6.0.2)

« previous php.general (#234548) next »