Jump to content

curl and cookies?


dbo

Recommended Posts

I'm trying to automate some login capability to an online service (webmail). I'm successfully posting the values to the page, but receiving a response that cookies are not enabled. Here's the code:

 

$url = "https://mail.mydomain.com/";
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "loginOp=login&username=user&password=pass&remember=0&client=preferred");

$result = curl_exec($ch);
curl_close($ch);

echo $result;

 

In the current directory I don't see any cookies which leads me to believe that the cookies are truly not being created. cURL isn't generating any error messages... is there some other way I'm not aware of for capturing errors?

 

Other potentially useful information. I'm running the above code on localhost (not the same server as the webmail resource). Though I don't think this matters because when I created a generic HTML form I could in fact login from localhost.

Link to comment
https://forums.phpfreaks.com/topic/125330-curl-and-cookies/
Share on other sites

Try ammending the cookie path to your server tmp directory. Had no problems setting cookies with curl using this:

 

$cookiePath = "/tmp/cookies.txt";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiePath);   
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiePath);

Link to comment
https://forums.phpfreaks.com/topic/125330-curl-and-cookies/#findComment-648623
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.