I can not login with cURL in PHP. URL does not change

0

I am trying to login to a system using cURL. But I can not log in, I think the problem is redirection.

I have a website (mysite.com) that has a form. this form calls the submit.php page. On this page I have the following code

<?php
//pega os inputs através do furmulário vindo do método POST.
$login  = $_POST['login'];
$senha  = $_POST['senha'];

$ch = curl_init();
$data['login']  = $login;
$data['senha']  = $senha;
$data['submit'] = 'true';
$dataall = http_build_query($data);


curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL, 'http://sistemaweb/login.php');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataall);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, 'http://sistemaweb/dashboard.php');
$a = curl_exec($ch);

echo $a;

curl_close($ch);
?>

The problem occurs when it calls the page. it play to the url myite.com / dashboard.php instead of systemweb / dashboard.php

The url does not leave my domain. I have tried in many ways but I have not been successful. even tried a header location but it seems that he realizes the session.

Is there any more missing parameters in the CURL process?

    
asked by anonymous 06.10.2018 / 07:27

1 answer

0

I think the only possibility of this is because sistemaweb/dashboard.php is using a redirect via Javascript or <meta> .

In this situation, sistemaweb/dashboard.php returns a <meta http-equiv="refresh" content="0; url=/dashboard" /> , or something similar. Since you are using echo $a , you end up giving print in that HTML / JS, so the response redirects the user.

Try to give echo htmlentities($a); and see if the behavior persists.

    
03.11.2018 / 04:05