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?
Tried to change
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
fortrue
?– Rafael Withoeft
Yes @Rafaelwithoeft, don’t make a difference.
– Luis Henrique