This question is similar to this older question.
The solution there seemed to work for me, but I get the result as not logged in. I get the page in the second request, but not as the user. What should I change? Here is the code:
<?php
$urlini='https://www.example.com/login';
$url='https://www.example.com/page-12345';
$ch = curl_init();
$fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_URL, $urlini);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/certificate.pem");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('email' => 'email@example.com' , 'password' => 'password')));
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$store = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
When I instead of echoing $response
, echo $store
, I see that the username is filled in the form, but the password is not. The code for the login form on the site is:
<div class="form_wrapper"><div class="form" id="login_form">
<span class="form_title hidden-xs">Log in</span><input id="email" name="id" type="email" placeholder="Email address" class="validate[required,custom[email]]"/>
<input id="password" name="password" type="password" placeholder="Password" class="validate[required,minSize[5],custom[passwordLegalChars]]"/><a
id="login_button" class="css_button css_button_big css_button_default" role="button" tabindex="0" >Log in</a>