-5

I am trying to automatically log in with Curl on this site: https://online.hinode.com.br, and the consultant ID must be filled in automatically, along with the status that will always be the same, after login should be redirected to a specific product page. However, the codes I tested did not go anywhere! No error, html does not load ... I think it should be this select field, I do not know.

Code:

<?php
// Start cURL
$ch = curl_init();
// Define the original URL (of the login form)
curl_setopt($ch, CURLOPT_URL, 'https://online.hinode.com.br/');
// Enable POST protocol
curl_setopt ($ch, CURLOPT_POST, 1);
// Define the parameters that will be sent (user and password for example)
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'loja_consultor=fulano&estado=SP');
// Imitate the boss behavior of browsers: handle cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
// Set the transfer type (Padrão: 1)
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// Execute the requisition
$store = curl_exec ($ch);
// Define a new URL to be called (after login)
curl_setopt($ch, CURLOPT_URL, 'https://online.hinode.com.br/detalhes.asp?IdProduto=769&ssp=830852727SSP20171218HP115020');
// Execute the second request
$content = curl_exec ($ch);

// Close cURL curl_close ($ch);

Thanks in advance!

enter image description here

enter image description here

enter image description here

enter image description here

1 Answers1

0

This will work:

<?php
$cookie="cookie.txt";
$login_url = "https://online.hinode.com.br/loja_valida.asp";
$target_url="https://online.hinode.com.br/detalhes.asp?IdProduto=1294&ssp=1044632862SSP20171218HP180256";
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

$field['loja_consultor'] = '228621';
$field['estado'] = 'SP';
$field['acessar'] = 'Acessar';

$datafield = http_build_query($field);

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datafield);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $target_url);
$ket_qua = curl_exec($ch);

echo $ket_qua;

curl_close($ch);
?>
tbedner
  • 323
  • 1
  • 10
  • Tks, but when I try this, this happens from here: https://i.stack.imgur.com/TmDBs.png – Leonardo Santos Dec 18 '17 at 19:00
  • If you go to the site and login normally, does it behave as you expect? – tbedner Dec 18 '17 at 19:03
  • Your image shows you get a 302 redirct to the index page. – tbedner Dec 18 '17 at 19:04
  • When I go to the site and I get it, he behaves normally. But when I run the php file, nothing is populated. – Leonardo Santos Dec 18 '17 at 19:10
  • I put the link that was directed and nothing happened. – Leonardo Santos Dec 18 '17 at 19:10
  • So it appears the curl is working correctly, and there is an issue with the site itself.Once that is resolved, the curl should work as well. If it doesn't, let me know and we can work on it. – tbedner Dec 18 '17 at 19:15
  • The site is working properly, so the curl should also, I do not know what is happening – Leonardo Santos Dec 18 '17 at 19:18
  • OK, if you go to the site itself at https://online.hinode.com.br/detalhes.asp?IdProduto=769&ssp=830852727SSP20171218HP115020, you are then presented with a login screen. You type in the consultant ID and the state, hit the submit button and then what happens? – tbedner Dec 18 '17 at 19:21
  • I'm redirected to the normal page:https://i.stack.imgur.com/k4678.png – Leonardo Santos Dec 18 '17 at 19:29
  • Are those the correct credentials (fulano and SP)? I am redirected back to the login page with them? – tbedner Dec 18 '17 at 19:42
  • To clarify, I do not need the correct credentials, but I want to make sure the correct ones were put in the curl request to rule that issue out. – tbedner Dec 18 '17 at 20:01
  • The correct credentials are: $field['loja_consultor'] = '228621'; $field['estado'] = 'SP'; ('estado' is a field type select) – Leonardo Santos Dec 18 '17 at 20:14
  • the form is posting to loja_valida.asp so it might help to look at that file and see if we are missing anything it expects us to post. I am still getting a 302 redirect to the index page. – tbedner Dec 18 '17 at 20:33
  • I've put up another code, but it's giving "moved object". I do not know what's going on. – Leonardo Santos Dec 18 '17 at 20:43