I wanted to send Post data via Curl to login and parse website pages. I've tried to send 'email' and 'password' via Curl but the response is null. I think the problem is that in the form there are other fields like "remember me" but I don't know how to inserts this values in CURL Post.
This is the html form
<form action="/account/login" method="post" >
<input type="hidden" name="targetUri" value="/a/site"/>
<fieldset class="table">
<table>
<tr>
<th>
<label for="email">E-mail:</label>
</th>
<td>
<input type="email" class="first_input value "
id="email" name="email" size="40" value=""/>
<div class="error">
</div>
</td>
</tr>
<tr>
<th>
<label for="password">Password:</label>
</th>
<td>
<input type="password" class="value "
id="password" name="password" size="40" value=""/>
<div class="error">
</div>
</td>
</tr>
<tr>
<th></th>
<td>
<div class="input">
<input type="hidden" name="_rememberMe" /><input type="checkbox" name="rememberMe" id="rememberMe" /> <span>Ricordami</span>
</div>
</td>
</tr>
<tr>
<th></th>
<td>
<input class="inputsubmit input" type="submit" name="submit" value="Accedi">
</td>
</tr>
</table>
</fieldset>
and this is the CURL
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$fields = array('email' => 'my@email.com', 'password' => 'mypassword',);
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$url = "https://service.threadvine.eu/account/login";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Tells cURL to follow redirects
$output = curl_exec($ch);
print $output;
// Get Login page and its cookies and save cookies in the temp file
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // Stores cookies in the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
// Post login form and follow redirects
$url_to_grab = "https://service.threadvine.eu/a/site";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url_to_grab);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$doc = new DOMDocument();
$doc->loadHTML($output);
Where am I wrong???
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$fields = array('email' => 'my@email.com', 'password' => 'mypassword',);
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$url = "https://service.threadvine.eu/account/login";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Tells cURL to follow redirects
$output = curl_exec($ch);
print $output;
// Get Login page and its cookies and save cookies in the temp file
// **$ch = curl_init(); <= Disable**
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // Stores cookies in the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
// Post login form and follow redirects
$url_to_grab = "https://service.threadvine.eu/a/site";
// **$ch = curl_init(); <= Disable**
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url_to_grab);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$doc = new DOMDocument();
$doc->loadHTML($output);