curl does not apply

1

I am creating a script that makes login on a page and returns me the HTML of the page /logado , but it is not working and from what I saw the code is correct

Where did I go wrong?

<?php

if(!empty($_POST["bin"])){
$bin = $_POST["bin"];
$email = explode("|", $bin)[0];
$senha = explode("|", $bin)[1];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://minhaconta.payleven.com.br/login_check");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, '_username=' . urlencode($email) . '&_password=' . urlencode($senha));

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$dados = curl_exec($ch);

echo "$dados";

}else{ echo 'erro'; }
?>
    
asked by anonymous 10.07.2017 / 01:49

1 answer

2

When you use CURLOPT_COOKIESESSION you force cURL to skip session cookies, consider "session cookies" as cookies that do not have a date to expire.

When you send the request to /login_check it stores cookies in cookie.txt (set to CURLOPT_COOKIEJAR ). When the login / password combination is valid, it will redirect to another page, this page will be followed by CURLOPT_FOLLOWLOCATION and will use cookies previously saved due to CURLOPT_COOKIEFILE .

However, with the combination of CURLOPT_COOKIESESSION this new request will not contain session cookies.

Remove curl_setopt($ch, CURLOPT_COOKIESESSION, true); or set to false , which is the default.

    
10.07.2017 / 02:29