Reputation: 889
I'm trying to login to a remote site using CURL but I just keep getting the error message your session has expired, please re-login.
$username="xxxxxx";
$password="yyyyyyyy";
$url="https://remotesite.com/my.activation.php3";
$cookie="cookie.txt";
$postdata = "username=".$username."&password=".$password;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, 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 ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
// check for errors before close
$result = curl_exec($ch);
echo $result;
curl_close($ch);
The cookie file is writeable and something is getting written to it. Any ideas what I can try to keep the session going?
Upvotes: 0
Views: 2873
Reputation: 20899
Make sure you're using the correct option for CURLOPT_COOKIE*
.
CURLOPT_COOKIEJAR
- The name of a file to save all internal cookies to when the handle is closed, e.g. after a call to curl_close.
CURLOPT_COOKIE
- The contents of the "Cookie: " header to be used in the HTTP request. Note that multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")
CURLOPT_COOKIEFILE
- The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file. If the name is an empty string, no cookies are loaded, but cookie handling is still enabled.
Additionally, enabling CURLOPT_VERBOSE
may be of assistance when debugging cURL.
Upvotes: 1