0

My problem is that in the second CURL the token has already changed because a new request is made ... is it possible to capture the token in a single request and send the postdata?

/// THE RANDON TOKEN BY URL

<input id="clipping" type="hidden" value="2163b6627c8b76e4c0dfbc38317769d003d3320df7002ee22fb31253fdb7a54fa4eec8c8e149c73ba3fa720280b85145">

My curl

<?php 

function getStr2($dado, $string, $string2){ 
    // FUNCTION QUE PUXA UM VALOR INDEFINIDO ENTRE DUAS STRINGS QUE NÃO MUDAM.
    preg_match_all("($string(.*)$string2)siU", $dado, $match1);
    return $match1[1][0];
}

/// GET TOKEN
$random = rand(10000, 100000000); // ISSO AQUI É UM RANDOM QUE EU FIZ APENAS PRA ELE GERAR O COOKIE SEM O MESMO NOME (PRA NAO DAR CONFLITO)
$ch = curl_init(); // INICIA O CURL
curl_setopt($ch, CURLOPT_URL, "https://www.mysite.com.br/login"); // URL ONDE VAI SER FEITA A REQ
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/kasdmklm'.$random.'.txt'); // AQUI VAI SER ONDE OS COOKIES VÃO SER GRAVADOS
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // DIZ QUE NÃO VAI VERIFICAR O PEER (HTTPS)
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // DIZ QUE NÃO VAI VERIFICAR O HOST (HTTPS)
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: www.mysite.com.br", "Connection: keep-alive", "Accept: text/javascript, text/html, application/xml, text/xml, */*; q=0.01", "X-Requested-With: XMLHttpRequest", "Content-Type: application/x-www-form-urlencoded", "")); // CABEÇALHO DO SITE
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"); // DIZ O USER AGENT [ NAVEGADOR ] QUE FOI FEITA A REQUISICAO
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // DIZ QUE VAI MOSTRAR O RESULTADO
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // DIZ QUE VAI SEGUIR CODIGOS REDIRECT
$data = curl_exec($ch); // EXECUTA O CURL
curl_setopt($ch, CURLOPT_VERBOSE, true);
$token = getStr2($data, '<input id="clipping" type="hidden" value="', '" />'); // O TOKEN VAI SER ARMAZENADO NESSA VARIAVEL

/// SEND POSTDATA TO LOGIN
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, 'https://www.mysite.com.br/login');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$email.'&password='.$senha.'&recaptchaResponse=&clipping='.$token.'');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, false);
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd() . '/cookie9999991.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd() . '/cookie9999991.txt');
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Host: www.mysite.com.br',
    'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:51.0) Gecko/20100101 Firefox/51.0',
    'Content-Type: application/x-www-form-urlencoded',
    'Referer: https://www.MYSITE.com.br/login',
    'Connection: keep-alive'
));

$login = curl_exec($ch);

?>
Peter
  • 29,454
  • 5
  • 48
  • 60
  • The token is generated for a particular session normally. So if you keep same session between your curls the token you get with the first will be valid with the second. The cookie filename seems to be different in the 2 curls. One is a random name the other is fixed. – oliver de Cramer Apr 03 '18 at 15:11
  • And how can I do this? – Geraldo Magela Apr 03 '18 at 15:22

0 Answers0