Log into a system via Curl and display data from another page

Asked

Viewed 1,523 times

1

I am trying to display the contents of a page after logging in to the system.

The login is done successfully, I receive the welcome from the system, but when changing the URL and making a new curl_exec receiving http_code = 302, but accessing via browser the page normally exists.

$username = $_GET['username'];
$password = $_GET['password'];
$data = array('josso_cmd' => 'login', 'josso_username' => $username, 'josso_password' => $password);

$url = "...";
$referer = "...";
$user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36";
$url_notas = "...";
$referer_notas = "...";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__). '/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);

print_r(curl_exec($ch));
print_r(curl_errno($ch));
print_r(curl_getinfo($ch));

echo "<hr>";

curl_setopt($ch, CURLOPT_URL, $url_notas);
curl_setopt($ch, CURLOPT_REFERER, $referer_notas);
curl_setopt($ch, CURLOPT_POST, 0);

print_r(curl_exec($ch));
print_r(curl_errno($ch));
print_r(curl_getinfo($ch));

The return is:

HTTP/1.1 302 Moved Temporarily

It returns me the login URL, as if I had lost section.

My question is where I’m going wrong?

  • 1

    Tried to change curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);for true?

  • Yes @Rafaelwithoeft, don’t make a difference.

1 answer

0


Problem solved.

Really was the CURLOPT_FOLLOWLOCATION, I’ll put it on the server I was testing php on safe_mode and did not perform the redirect.

I set the CURLOPT_FOLLOWLOCATION = true and I went to another server, in this I obtained success and the return of the expected page.

Browser other questions tagged

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