Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.