-2

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>
Community
  • 1
  • 1
Ernst
  • 103
  • 1
  • 3
  • 8
  • Possible duplicate of [cURL Login to HTTPS site](http://stackoverflow.com/questions/8318041/curl-login-to-https-site) – B001ᛦ Jan 25 '17 at 10:12
  • @bub: I stated that the question is similar, I tried the solution there and it did not solve the problem for me. The question here is not a duplicate of that other question, since the answer to that other question is my starting point. – Ernst Jan 25 '17 at 11:24
  • Maybe you're missing some post fields for logging in, or another common issue is the lack of sending a User-Agent string. Hard to say without seeing the output, and the source of the login page to know if anything is missing. – drew010 Jan 25 '17 at 16:02

1 Answers1

0

I've managed to solve the problem. It turned out the login page did send the login first to some bot prevention site. Using developer->inspector->network with enable persistent logs gave me the real login url. After changing $urlini accordingly, the code worked.

Ernst
  • 103
  • 1
  • 3
  • 8