Doubt with PHP file_get_contents

Asked

Viewed 2,100 times

0

my code running on the pc works 100% but when I play on the server it does not capture the information. follows code so that you help me

<link type="text/css" rel="stylesheet" href="http://jsuol.com.br/c/_template/v1/_geral/css/styles.css?&file=geral&type=parse&versao=v1&plataforma=web&portal=uol&media=webpage&cache=19t3e89gn" />
<link type="text/css" rel="stylesheet" href="http://jsuol.com.br/c/_template/v1/_geral/css/styles.css?&file=especifico&type=parse&versao=v1&plataforma=web&portal=uol&estacao=economia&estacao-id=economia&cache=19t3e89gn" />
<link type="text/css" rel="stylesheet" href="http://jsuol.com.br/c/_template/v1/web/uol/css/internas/economia/cotacoes/styles-cotacoes.css?&cache=19t3e89gn" />
<link type="text/css" rel="stylesheet" href="http://jsuol.com.br/c/economia/cotacoes/cotacoes.css?v13&&cache=19t3e89gn" />
<link type="text/css" rel="stylesheet" href="http://jsuol.com.br/c/_template/v1/web/uol/css/estrutura/conteudo-auxiliar.css?&cache=19t3e89gn" />
<?php

$url = file_get_contents('http://economia.uol.com.br/cotacoes/');
preg_match_all('/<section class="barra-ticker pg-bgcolor3">(.+)<\/p> <\/li> <\/ul> <\/div> <\/section>/s', $url, $conteudo);
$exibir = $conteudo[0][0];
$retirar = array('');
$exibir = str_replace($retirar, '', $exibir);
echo $exibir;
                ?>
  • You already gave CHMD 777 in the file folder?

  • may be chmod 775.

  • Maybe you need to enable: ini_get('allow_url_open') or ini_set('allow_url_fopen', 1)não precisa ir até ophp.ini` if you don’t have access.

  • If you want you can do it for the . htaccess file, just put this rule on it: php_value allow_url_fopen On

  • when giving CHMD 775 in the folder generates an error on the page Internal Server Error The server encountered an Internal error or misconfiguration and was Unable to complete your request. Please contact the server Administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Apache/2.4.12 (Unix) Openssl/1.0.1e-Fips mod_bwlimited/1.4 Server at ruralrio.com.br Port 80

  • http://ruralrio.com.br/bolsa/bolsauol.php

  • error_reporting is enabled?

  • this, is the funniest and that has another page that shows right that the part of rural quotes.com.br/corn.php

Show 3 more comments

1 answer

1


Go to the file php.ini and change the following lines;

Of: allow_url_fopen = Off

To: allow_url_fopen = On

If you do not have access to php.ini you can also use;

ini_get('allow_url_open') or ini_set('allow_url_fopen', 1)

if it doesn’t work...

You can also use CURL to do this, right after the opening of the PHP tag on your page in question put the code below:

function my_file_get_contents( $site_url ){
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
ob_start();
curl_exec($ch);
curl_close($ch);
$file_contents = ob_get_contents();
ob_end_clean();
return $file_contents;
}

Now instead of using file_get_contents('http://.....') Voce can use my_file_get_contents('http://.....')

I found in some foruns the following phrase:

The problem will be fixed, the use of the file_get_contentes function is a serious security flaw, it is recommended to create the Curl function above.

  • by my phpinfo these functions are active (http://ruralrio.com.br/phpinfo.php)

  • shows no error @Cristianocardososilva ?

  • Not a single mistake

  • and the funniest and that has another page that shows right that the part of quotations http://ruralrio.com.br/milho.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.