I have a problem with curl. When I use this code in apache installed on Windows 10, it always works. When I use it on Linux, both on Ubuntu Server 16.04 and on CentOS 7, it gives both problems, sometimes it works after several attempts (1 in 5 on average). What is missing in the Linux configuration? Something related to cookware storage? I'm almost installing Windows Server 2012.: (
<?php
print buscaPagina();
function buscaPagina()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch,CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//curl_setopt($ch, CURLOPT_HEADER, true);
//curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH,true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, 'https://eproc1.tjto.jus.br/eprocV2_prod_1grau/externo_controlador.php?acao=entrar&alt=21');
curl_setopt($ch, CURLOPT_POSTFIELDS,'selSistema=2&txtUsuario=nomedeusuario&pwdSenha=aquiasenha');
$retorno = curl_exec($ch);
curl_close($ch);
return $retorno;
}