Hey guys,
I'm having a helluv a time trying to get cURL working with the cookiejar. The idea is that I should be able to make a request to the login page to start the session, then use cURL to hit other pages to collect informatino.
I can login with the first request, this works fine. I then check the cookie file I've set and the data is in there. When I make the second connection it has lost the session. The headers indicate that it is using a different session id, and the cookie file does not get updated.
I'm at a loss on how I can get this thing to have a persistent connection, any help would be much appreciated.
Here is a sloppy version of what I'm working with.
$ch = curl_init();
$cookie_file_path = 'my_cookie.txt';
$cookie_file_path = realpath($cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
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_FOLLOWLOCATION, 1);
//new ones
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL,"https://myurl/login.php?login=user&password=password");
echo curl_exec ($ch); // execute the curl command
echo 'Curl error: ' . curl_error($ch); //no errrors
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
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_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL,"https://myurl/report.php?option1=value1&option2=value2");
//new ones
curl_setopt($ch, CURLOPT_HEADER, 1);
echo curl_exec ($ch);
echo 'Curl error: ' . curl_error($ch);
curl_close ($ch);
I've tried it as both get and post. Adding the header opt is new and appears to have made no difference other then allowing me to confirm my session id is changing. Am I even going about this the right way?