Log in to a system via cURL and display data from another page

0

I'm trying to display the contents of a page after logging into the system.

The login is successful, I receive the welcome from the system, however when I change the URL and make a new curl_exec I get http_code = 302 , but accessing via the browser 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 to the login URL, as if it had lost section.

My question is Where am I going wrong?

    
asked by anonymous 14.04.2015 / 20:43

1 answer

0

Problem solved.

I really was CURLOPT_FOLLOWLOCATION , I'll put in the server that was testing php was in safe_mode and did not perform redirection.

I set the CURLOPT_FOLLOWLOCATION = true and I ran on another server, this succeeded and returned the expected page.

    
15.04.2015 / 17:33