Joe Fruchey Joe Fruchey -4 years ago 197
PHP Question

Can't seem to get CURLOPT_SSL_VERIFYPEER to behave in PHP

Ultimately, I'm trying to set up a simple site with links that initiate a cURL POST using basic auth. The href of the link points to

blah.php?dothething
.

In the php file, I have

if ($_SERVER['QUERY_STRING'] == 'dothething') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://blah/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "thing=1&do=true");
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
curl_setopt($ch, CURLOPT_PIPEWAIT, TRUE); //POST takes about 10 sec to process
curl_setopt($ch, CURLOPT_SSLVERIFYPEER, FALSE); //self-signed cert
curl_exec($ch);
curl_close($ch);
}


When I visit the link, I get:

Warning: curl_setopt() expects parameter 2 to be integer, string given in blah.php on line 31

Warning: curl_setopt() expects parameter 2 to be integer, string given in blah.php on line 32


I've tried
TRUE
,
true
,
"true"
, and
1
, and have gotten the same error every time.

I'm running this on PHP v7.0.14 on DreamHost. Looks like these options have been available since v7.0.7, are they maybe just not available in DreamHost's PHP? If that's the case, is there any way to not validate the cert, other than running it somewhere else?

Answer Source

You're missing an underscore:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

Or even better, just go to https://letsencrypt.org/ and get yourself a real cert for free.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download