I'm really confused by this. My company recently switched this URL to https, and I can no longer make cURL requests against it. No one else in the company does PHP, so there's no one to help me debug.
I don't have much experience with https, so I read through a bunch of posts on here and found a few that addressed this same issue, namely, this one:
Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?
At first, I was getting all sorts of errors related to security certificates, but after adding curl.cainfo="c:\xampp\htdocs\login\cacert.pem"
to my php.ini
file, I believe I have resolved those as I am not getting errors anymore, but I am still not getting back a successful login response.
As part of the process, I need to pass a cookie to the server, which is present. echo $strCookie
gives back the correct cookie data, so I don't think it's that.
$searchURL = "https://url.com/valid?";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $searchURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$strCookie = 'testcookie=' . $_COOKIE['testcookie'] . '; path=/';
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
curl_setopt($ch, CURLOPT_CAPATH, "\cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
if($answer = curl_exec($ch))
{
echo "<pre>";
print_r($answer);
echo "</pre>";
}
else
{
echo "<pre>";
echo 'Curl error: ' . curl_error($ch);
echo "</pre>";
}
If I put the url into my browser (url.com/valid?
), I get back boolean = true
, so I know I am logged in. However, this script is returning boolean = false
and I cannot figure out why.
Here are the headers:
TTP/1.1 200 OK
Date: Mon, 09 Nov 2015 21:33:16 GMT
Cache-Control: no-store, no-cache, must-revalidate, max-age=0
Pragma: no-cache
Content-Length: 14
Content-Type: text/plain; charset=UTF-8
X-Powered-By: Servlet/2.5 JSP/2.1
Set-Cookie: amlbcookie=01; domain=.****.com; path=/
Vary: User-Agent,Accept-Encoding
I'm confused by the Set-Cookie: amlbcookie=01
line, as I'm not sure what that cookie is. It does not match the output I get from echo $strCookie
.