Erro PHP: Undefined offset: 1
Boa noite,
O script abaixo funciona no meu wamp localhost, porem quando executo ele em meu servidor linux ubuntu apresenta os seguintes erros:
Notice: Undefined offset: 1 in /var/www/html/legado/index.php on line 82
Notice: malformed in /var/www/html/legado/index.php on line 92
Esse é meu script:
<?php
ini_set( 'display_errors', true );
error_reporting( E_ALL );
$url1 = 'https://gw-homologa.serasa.com.br/Logon/LogonGR.aspx?apl=https://sitenet05.serasa.com.br/DemonstrativoSintetico/Demonstrativos/DemonstrativoSinteticoPrincipal.aspx';
$userAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36";
$login = '***';
$senha = '***';
// ?cnpj=***&inicio=16/12/2014&fim=15/01/2015
$cnpj = '***';
$dataInicio = '16/01/2015';
$dataFim = '15/02/2015';
// REQUISI?O 1 (PARA SETAR O COOKIE) -----------------------------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
preg_match('/Set-Cookie:(.*?);/',$result,$m);
$cookie1 = trim($m[1]);
preg_match('/Location:(.*)/',$result,$m);
$url2 = trim($m[1]);
// REQUISI?O 2 (PARA PEGAR OS VALORES DOS CAMPOS HIDDEN -------------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie1
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
$post = [];
//preg_match('/<input.*?__EVENTTARGET.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTTARGET='.urlencode('uctLogon:btSubmit');
preg_match('/__EVENTARGUMENT.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTARGUMENT='.urlencode($m[1]);
preg_match('/__LASTFOCUS.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__LASTFOCUS='.urlencode($m[1]);
preg_match('/__VIEWSTATE.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATE='.urlencode($m[1]);
preg_match('/__VIEWSTATEGENERATOR.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATEGENERATOR='.urlencode($m[1]);
preg_match('/__EVENTVALIDATION.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTVALIDATION='.$m[1];
$post[] = urlencode('uctLogon:txtUsuario').'='.$login;
$post[] = urlencode('uctLogon:txtSenha').'='.$senha;
$postdata = implode("&",$post);
// REQUISI?O 3 (PARA EFETUAR O LOGIN) ---------------------------------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url2);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie1
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
preg_match('/Location:(.*)/',$result,$m);
$url4 = trim($m[1]);
// REQUISI?O 4 (PARA RECEBER NOVO COOKIE) --------------------------------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
preg_match('/Set-Cookie:(.*?);/',$result,$m);
$cookie2 = trim($m[1]);
preg_match('/Location:(.*)/',$result,$m);
$url5 = trim($m[1]);
// REQUISI?O 5 (CHEGANDO NA TELA PARA INSERIR O CNPJ) ---------------------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie2
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
$post = [];
preg_match('/<input.*?__EVENTTARGET.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTTARGET='.urlencode($m[1]);
preg_match('/<input.*?__EVENTARGUMENT.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTARGUMENT='.urlencode($m[1]);
preg_match('/<input.*?__LASTFOCUS.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__LASTFOCUS='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATE.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATE='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATEGENERATOR.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATEGENERATOR='.urlencode($m[1]);
preg_match('/<input.*?__EVENTVALIDATION.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTVALIDATION='.urlencode($m[1]);
$post[] = urlencode('ctl00$Conteudo$txtCNPJ') . "=$cnpj";
$post[] = urlencode('ctl00$Conteudo$imgBuscarDadosCliente.x') . '=0';
$post[] = urlencode('ctl00$Conteudo$imgBuscarDadosCliente.y') . '=0';
$post[] = urlencode('ctl00$Conteudo$txtDataInicio') . '=';
$post[] = urlencode('ctl00$Conteudo$txtDataFim') . '=';
$post[] = urlencode('ctl00$Conteudo$rdbTipoVisao') . '=F';
$post[] = urlencode('ctl00$Conteudo$rdbFormatoVisualizacao') . '=H';
$post[] = urlencode('ctl00$Conteudo$rdbNivelArquivo') . '=P';
$postdata = implode("&",$post);
// REQUISI?O 7 - BLUR DO CAMPO DE CPF
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url5);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie2
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
$post = [];
preg_match('/<input.*?__EVENTTARGET.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTTARGET='.urlencode($m[1]);
preg_match('/<input.*?__EVENTARGUMENT.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTARGUMENT='.urlencode($m[1]);
preg_match('/<input.*?__LASTFOCUS.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__LASTFOCUS='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATE.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATE='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATEGENERATOR.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATEGENERATOR='.urlencode($m[1]);
preg_match('/<input.*?__EVENTVALIDATION.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTVALIDATION='.urlencode($m[1]);
$post[] = urlencode('ctl00$Conteudo$txtCNPJ') . "=$cnpj";
$post[] = urlencode('ctl00$Conteudo$txtDataInicio') . "=$dataInicio";
$post[] = urlencode('ctl00$Conteudo$txtDataFim') . '=';
$post[] = urlencode('ctl00$Conteudo$rdbTipoVisao') . '=F';
$post[] = urlencode('ctl00$Conteudo$rdbFormatoVisualizacao') . '=H';
$post[] = urlencode('ctl00$Conteudo$rdbNivelArquivo') . '=P';
$postdata = implode("&",$post);
// REQUISI?O 8 - BLUR DO DATA INICIO
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url5);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie2
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
$post = [];
preg_match('/<input.*?__EVENTTARGET.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTTARGET='.urlencode($m[1]);
preg_match('/<input.*?__EVENTARGUMENT.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTARGUMENT='.urlencode($m[1]);
preg_match('/<input.*?__LASTFOCUS.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__LASTFOCUS='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATE.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATE='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATEGENERATOR.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATEGENERATOR='.urlencode($m[1]);
preg_match('/<input.*?__EVENTVALIDATION.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTVALIDATION='.urlencode($m[1]);
$post[] = urlencode('ctl00$Conteudo$txtCNPJ') . "=$cnpj";
$post[] = urlencode('ctl00$Conteudo$txtDataInicio') . "=$dataInicio";
$post[] = urlencode('ctl00$Conteudo$txtDataFim') . "=$dataFim";
$post[] = urlencode('ctl00$Conteudo$rdbTipoVisao') . '=F';
$post[] = urlencode('ctl00$Conteudo$rdbFormatoVisualizacao') . '=H';
$post[] = urlencode('ctl00$Conteudo$rdbNivelArquivo') . '=P';
$postdata = implode("&",$post);
// REQUISI?O 9 - BLUR DE DATA FIM
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url5);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie2
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
$post = [];
preg_match('/<input.*?__EVENTTARGET.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTTARGET='.urlencode($m[1]);
preg_match('/<input.*?__EVENTARGUMENT.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTARGUMENT='.urlencode($m[1]);
preg_match('/<input.*?__LASTFOCUS.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__LASTFOCUS='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATE.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATE='.urlencode($m[1]);
preg_match('/<input.*?__VIEWSTATEGENERATOR.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__VIEWSTATEGENERATOR='.urlencode($m[1]);
preg_match('/<input.*?__EVENTVALIDATION.*?value.*?[\"\'](.*?)[\"\']/',$result,$m);
$post[] = '__EVENTVALIDATION='.urlencode($m[1]);
$post[] = urlencode('ctl00$Conteudo$txtCNPJ') . "=$cnpj";
$post[] = urlencode('ctl00$Conteudo$txtDataInicio') . "=$dataInicio";
$post[] = urlencode('ctl00$Conteudo$txtDataFim') . "=$dataFim";
$post[] = urlencode('ctl00$Conteudo$rdbTipoVisao') . '=F';
$post[] = urlencode('ctl00$Conteudo$rdbFormatoVisualizacao') . '=E';
$post[] = urlencode('ctl00$Conteudo$rdbNivelArquivo') . '=P';
$post[] = urlencode('ctl00$Conteudo$btnGerarRelatorio') . '=Gerar Relat?io';
$postdata = implode("&",$post);
// REQUISI?O 10 - BUSCANDO OS DADOS
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_URL,$url5);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie:'.$cookie2
]);
if(($result = curl_exec($ch)) === false) trigger_error(curl_error($ch));
curl_close($ch);
// SEPARANDO OS HEADERS
preg_match('/<tr>(.*?)<\/tr>/s',$result,$m);
preg_match_all('/<td>(.*?)<\/td>/s',$m[1],$m);
$headers = $m[1];
// SEPARANDO OS DADOS
$dados = [];
preg_match_all('/<tr>\s*(<td align=\"justify\">.*?)<\/tr>/s',$result,$m);
foreach($m[1] as $line){
preg_match_all('/<td.*?>(.*?)<\/td>/',$line,$m2);
$linha_dados = [];
foreach($headers as $key => $value){
$linha_dados[$value] = $m2[1][$key];
}
//var_dump($linha_dados);
$dados[] = $linha_dados;
}
echo '<pre>' . print_r($dados, 1) . '</pre>';
?>Discussão (6)
Carregando comentários...