I am trying my first PHP CLI using cURL, and simply want to complete a login to an HTTPS site. The site HTML is simple:
<body>
<div class='plain-header'>
<img src='/images/logo.jpg' />
</div>
<div class='login-form'>
<form method='post'>
<table>
<tr>
<td class='fieldname'>Username:</td>
<td>
<input name='login' type='text' />
</td>
</tr>
<tr>
<td class='fieldname'>Password:</td>
<td>
<input name='password' type='password' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' value='Login' />
</td>
</tr>
</table>
</form>
</div>
</body>
and I tried
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://mysite.com/');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/BuiltinObjectToken=GoDaddyClass2CA.crt");
curl_setopt($ch, CURLOPT_POST, 1) ;
$login = 'mylogin';
$pwd = 'mypassword';
$postdata = "login=". $login ."&password=". $pwd;
curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
//$data=curl_exec($ch);
//echo $data;
curl_close($ch);
?>
as is the script echoes back it completed without error, but if uncomment the //$data lines I receive
<body>
<div class='plain-header'>
<img src='/images/logo.jpg' />
</div>
<h1>There was an error. Sorry about that.</h1>
</body>
The url, real login and password all work manually, and I don't really need the certificate info in order to open the url. I assume I am making a fundamental mistake in the code and would appreciate being corrected.
TIA