I cannot login with Curl in PHP. URL does not change

Asked

Viewed 282 times

0

I am trying to log into a system using Curl. But I am not able to log in, I believe the problem is the redirect.

I have a website (meusite.com.br) that has a form. this form calls the send page.php . 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 meusite.com.br/Dashboard.php instead of systemsweb/Dashboard.php

url does not leave my domain. I have tried it in many ways but I was unsuccessful. I even tried a header Location but it seems that it perceives the session.

Is there any more parameter missing in the CURL process ?

1 answer

1


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

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

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

Browser other questions tagged

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