Foros del Web » Programando para Internet » PHP »

file_get_contents() y curl no funcionan [AYUDAA]

Estas en el tema de file_get_contents() y curl no funcionan [AYUDAA] en el foro de PHP en Foros del Web. Cuando uso el file_get_contents() o el curl a páginas de mi dominio me tira este error: Warning: file_get_contents(mi pagina): failed to open stream: HTTP request ...
  #1 (permalink)  
Antiguo 12/12/2013, 20:10
 
Fecha de Ingreso: agosto-2012
Mensajes: 77
Antigüedad: 11 años, 8 meses
Puntos: 0
Pregunta file_get_contents() y curl no funcionan [AYUDAA]

Cuando uso el file_get_contents() o el curl a páginas de mi dominio me tira este error:
Warning: file_get_contents(mi pagina): failed to open stream: HTTP request failed! in on line 7

Pero cuando lo hago con un link externo si me sirve, no entiendo porqué pasa eso

Aquí está mi código PHP cuando le pongo el file_get_contents() ->
Código PHP:
Ver original
  1. <?php
  2. $options = array('http' =>
  3.     array( 'header' => 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; es-CL; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3' . PHP_EOL )
  4. );
  5. $context = stream_context_create($options);
  6. $page = file_get_contents('http://sicel.x10.mx/evaluacion.php', false, $context);
  7. echo $page;
  8. ?>

Y aquí está el otro código cuando lo intento hacer con curl:
Código PHP:
Ver original
  1. <?php
  2. $url= 'http://www.google.com';
  3. $ch = curl_init();
  4.     curl_setopt ($ch, CURLOPT_URL,$url);
  5.     curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
  6.     curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
  7.     curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  8.     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  9.     $text = curl_exec ($ch);
  10.     curl_close($ch);  
  11. echo "$text";
  12. ?>

Etiquetas: curl, funcionan
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:44.