Curl does not request

Asked

Viewed 401 times

1

I’m creating a script what makes login on a page and returns me the Htmlda page /logado, but it’s not working and from what I saw the code is correct

Where I went 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'; }
?>
  • What appears on the page? What is the end value of $dados?

  • I wish him to then go to https://minhaconta.payleven.com.br/dashboard and return me whatever is there

  • 1

    This did not answer the previous question. What appears on the screen and what is the value in $dados? You can use the function var_dump.

  • I don’t know if that’s it, but if you use the CURLOPT_COOKIESESSION as far as I know it starts a new session, discarding the session data that is on 'cookie.txt' (cookies that have no expiration date = session). That is, it will follow the location and will not use session cookies. I do not know if that is it, I am not confident that this is it, but try to remove this line. :)

  • Anderson in data would be the html of my request

  • See in the headers which is the way it goes. If it comes to the next page and goes back to the login page or if it never entered.

  • Remove the cookiesession solved the problem thanks buddy

Show 2 more comments

1 answer

2


When using the CURLOPT_COOKIESESSION you force Curl to ignore session cookies, consider "session cookies" as cookies that have no expiration date.


When you send the request to /login_check it stores cookies on cookie.txt (defined in CURLOPT_COOKIEJAR). When the login/password combination is valid it will redirect to another page, this page will be followed due to the 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 the curl_setopt($ch, CURLOPT_COOKIESESSION, true); or set to false, which is the standard.

  • could you help me? https://answall.com/questions/219104/bad-authentication-data-curl-twitter-api

  • I saw some answers from you and I saw one that you talk about basic Authentication. in my question I think I need this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.