Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

lucasdidur

[Resolvido] Erro com file_get_contents

Recommended Posts

Olá pessoal, estou com um problema aqui, quando eu carrego uma pagina numa string ela aparece cheio de erro.

 

Ela aparece mais ou menos assim

r#G ohVɺ'T%c*%E֣O[,,&2|df{W^tz32	H0RU$_\G>{jyP^/N_g^zj
hԬV*WfEś5ұs+fzVQw'sFCuW9⿑y	wnoE_}=ƁvfM9u몂`<bO><G:=;~
8a!O/r/u\H)=7!d<f@xGaw8z2b#c2
arW 1'ݰG_+tÙNYB׃uzM:`->tL;ǣ?|#(XW0@݄"FO3S[\ώ	N;k7#>3_GUdHgGO^ݠXg)`1
#pg:=dLY#^@QTD[D]˯<quy$33=׿$D8"@=YW=2xoC0F:
ݰSVh=:?0J#V<ih+x;^ܞ \><<эY0\q$hZqyEvKYgB=NQ61`P/O཮yv5kGe˓7GbMDY5:nDz^1e错gOgF#/P5ÿ_dUr
VO[}>

 

O que que isso quer dizer? Tem como arrumar?

O código que estou usando é esse:

 

$pg = file_get_contents("http://www.gamevicio.com.br/");

echo $pg;

Compartilhar este post


Link para o post
Compartilhar em outros sites

lucasdidur, esse erro parece erro de encoding então você pode tentar o seguinte:

<?php 
function file_get_contents_utf8($fn) { 
  $content = file_get_contents($fn); 
   return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); 
} 
?>

O scrip acima foi retirado do site php.net, o que ele faz é converter as coisas para o encoding correto.

 

Espero que ajude.

Vlws.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Usei a Primeira Função(Da UTF-8) e ficou assim:

 

í½Ër#G²(¸—Ùý‡ÌºU²fùÄKª’±ø*ªŠUì"«¤>ÇÚ` d1‘	å$ëêÎgÌØ|Â|Ã]Îjö³º«‘Ý…L׬W}ΦWãî‘	  ^ Twµ±U$îîáîááþí—ÇoŽ®ÿryÂzQße—ïž¿:?b^*ý`•JÇ×ÇìÇׯ˜^ÔØu ¼Ð‰ßn©tòºÀ
½(ÔK¥ÛÛÛâ­YôƒnéúméqéœüÊ£	Èb;jžý—/¾%Šw}ןÎÀ£×j5®KÑÆ#'rå³3Ñ—ï–ã3ξ÷»~xÀ®eËó]¿ëˆìh;þõ?%||ytÀ~4Ëüve°ÎÏØñþuyðmIa´}	æÖ§…¶[3ÀÎXË÷"éEOG¾×qÉDÈþáFNþõüèo-G‘hLoø·¶Äîï×	eÈ$¿
¡û)–,ð] ã³~ìµ}?°÷l Á­6¡“wÔß[ÇÁ¿æ9Ø	h,Y;,X)×ãyëíp¢»ã	zˆÐqažÞ°¾pü€L(·ÓêƒÖPøÐ9}ø
H»2
þÃsZþPéâH´ý:èŠû08[ÌÈþi&ÝWcjúw“=G†sùSìin±×üú~ 'ÆÉ»¨„ð
kõDÊèéùÕ^­Ú5®@%Z=É!Ìô.Ïç-ü

E a outra deu esse erro "Fatal error: Call to undefined function gzdecode() in /home/ehaqui/public_html/gerador/funcoes.teste.php on line 296"

 

Nessa linha tem isso

 

echo gzdecode(file_get_contents("http://www.gamevicio.com.br"));
 
if(!function_exists("gzdecode")) {
function gzdecode($data) {
  $len = strlen($data);
  if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
    return null;  // Not GZIP format (See RFC 1952)
  }
  $method = ord(substr($data,2,1));  // Compression method
  $flags  = ord(substr($data,3,1));  // Flags
  if ($flags & 31 != $flags) {
    // Reserved bits are set -- NOT ALLOWED by RFC 1952
    return null;
  }
  // NOTE: $mtime may be negative (PHP integer limitations)
  $mtime = unpack("V", substr($data,4,4));
  $mtime = $mtime[1];
  $xfl   = substr($data,8,1);
  $os    = substr($data,8,1);
  $headerlen = 10;
  $extralen  = 0;
  $extra     = "";
  if ($flags & 4) {
    // 2-byte length prefixed EXTRA data in header
    if ($len - $headerlen - 2 < 8) {
      return false;    // Invalid format
    }
    $extralen = unpack("v",substr($data,8,2));
    $extralen = $extralen[1];
    if ($len - $headerlen - 2 - $extralen < 8) {
      return false;    // Invalid format
    }
    $extra = substr($data,10,$extralen);
    $headerlen += 2 + $extralen;
  }
 
  $filenamelen = 0;
  $filename = "";
  if ($flags & 8) {
    // C-style string file NAME data in header
    if ($len - $headerlen - 1 < 8) {
      return false;    // Invalid format
    }
    $filenamelen = strpos(substr($data,8+$extralen),chr(0));
    if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
      return false;    // Invalid format
    }
    $filename = substr($data,$headerlen,$filenamelen);
    $headerlen += $filenamelen + 1;
  }
 
  $commentlen = 0;
  $comment = "";
  if ($flags & 16) {
    // C-style string COMMENT data in header
    if ($len - $headerlen - 1 < 8) {
      return false;    // Invalid format
    }
    $commentlen = strpos(substr($data,8+$extralen+$filenamelen),chr(0));
    if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
      return false;    // Invalid header format
    }
    $comment = substr($data,$headerlen,$commentlen);
    $headerlen += $commentlen + 1;
  }
 
  $headercrc = "";
  if ($flags & 1) {
    // 2-bytes (lowest order) of CRC32 on header present
    if ($len - $headerlen - 2 < 8) {
      return false;    // Invalid format
    }
    $calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
    $headercrc = unpack("v", substr($data,$headerlen,2));
    $headercrc = $headercrc[1];
    if ($headercrc != $calccrc) {
      return false;    // Bad header CRC
    }
    $headerlen += 2;
  }
 
  // GZIP FOOTER - These be negative due to PHP's limitations
  $datacrc = unpack("V",substr($data,-8,4));
  $datacrc = $datacrc[1];
  $isize = unpack("V",substr($data,-4));
  $isize = $isize[1];
 
  // Perform the decompression:
  $bodylen = $len-$headerlen-8;
  if ($bodylen < 1) {
    // This should never happen - IMPLEMENTATION BUG!
    return null;
  }
  $body = substr($data,$headerlen,$bodylen);
  $data = "";
  if ($bodylen > 0) {
    switch ($method) {
      case 8:
        // Currently the only supported compression method:
        $data = gzinflate($body);
        break;
      default:
        // Unknown compression method
        return false;
    }
  } else {
    // I'm not sure if zero-byte body content is allowed.
    // Allow it for now...  Do nothing...
  }
 
  // Verifiy decompressed size and CRC32:
  // NOTE: This may fail with large data sizes depending on how
  //       PHP's integer limitations affect strlen() since $isize
  //       may be negative for large sizes.
  if ($isize != strlen($data) || crc32($data) != $datacrc) {
    // Bad format!  Length or CRC doesn't match!
    return false;
  }
  return $data;
}
}

Sera que não pode ser o User Agent do PHP que foi bloqueado, pois com um site, no Navegador um Arquivo JS Aparecia mais no Dreamweaver Não, aparecia parecido com esse.

 

E no esta acontecendo o mesmo com esse site

Imagem Postada

 

Coloquei para Visualização Dinâmica e Coloquei o Site do GameVicio

 

Ou um script do Site?

 

Tem como mudar o User Agent do PHP?

 

Olá pessoal, descobri por que esta dando esse erro, pensei que não mais é, ele esta compactado com o GZip.

 

Achei um site que testa se o site esta compactado ou não:

http://www.dnsqueries.com/en/check_http_gzip.php

http://www.nibbleguru.com/tools/gzip-test.php

 

No Dreamweaver ele da esse erro porque ele não envia o Request para descompactar.

 

Pronto, por que ocorre já Sabemos o que esta acontecendo, mais agora, aleguem pode me ajudar com uma Função para descompactar usando o PHP?

 

Não tenho nem idéia de como fazer isso

 

Olá pessoal, consegui fazer o tréco anda, tava fazendo errado

 

Estava colocando assim

 

$file = "http://www.gamevicio.com.br/";'>http://www.gamevicio.com.br/"; 

echo gzdecode($$file)

e era por isso que estava dando erro, tinha que colocar o "file_get_contents" ficando assim.

 

$file = file_get_contents("http://www.gamevicio.com.br/"); 

echo gzdecode($$file)

Agora deu tudo certo, obrigado pela ajuda pessoal, o bom foi que eu aprendi mais(dizem que se aprende as coisas com os erros), já que estou começando no PHP

 

 

Valeu :D

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.