Foros del Web » Programando para Internet » PHP » Frameworks y PHP orientado a objetos »

problema con file_get_contents()

Estas en el tema de problema con file_get_contents() en el foro de Frameworks y PHP orientado a objetos en Foros del Web. Estoy tratando de echar a funcionar la clase wikipediaclass.php que me he bajado de phpclasses y me da el siguiente error cuando trato de abrir ...
  #1 (permalink)  
Antiguo 19/10/2007, 06:00
 
Fecha de Ingreso: febrero-2007
Mensajes: 103
Antigüedad: 17 años, 2 meses
Puntos: 0
problema con file_get_contents()

Estoy tratando de echar a funcionar la clase
wikipediaclass.php que me he bajado de phpclasses y me da el siguiente error
cuando trato de abrir la url

file_get_contents(http://es.wikipedia.org/wiki/historia) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in C:\wamp\www\wikipedia\wikipedia.class.php on line 14

el fichero php

<?PHP
include 'wikipedia.class.php';
$x = new wikipedia('http://es.wikipedia.org/');
echo $x->get_page('historia', true);
?>


y el codigo de la clase

<?PHP
class wikipedia
{
public function __construct($wiki)
{
$this->wiki = $wiki;
}
public function __destruct()
{
unset($this->wiki);
}
public function get_page($name, $header = false)
{
$file = file_get_contents($this->wiki.'wiki/'.$name);
$file = str_replace('href="/', 'href="'.$this->wiki.'/', $file);
//$file = str_replace('href="#', 'href="'.$this->wiki.'/wiki/'.$name.'#', $file);
preg_match_all('#<!-- start content -->(.*?)<!-- end content -->#es', $file, $ar);
unset($file);
IF(is_array($ar[1]))
{
IF($header == false)
{
return $ar[1][0];
}
else
{
return '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="'.$this->wiki.'/skins-1.5/monobook/main.css" /></head><body>'.$ar[1][0];
}
}
else
{
return false;
}
}
public function edit_page($name, $header = false)
{
$file = file_get_contents($this->wiki.'/w/index.php?title='.$name.'&action=edit');
preg_match_all('#<textarea (.*?)ols=\'80\' >(.*?)</textarea>#es', $file, $ar);
unset($file);
IF(is_array($ar[2]))
{
ob_start();
IF($header != false)
{
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="'.$this->wiki.'/skins-1.5/monobook/main.css" /></head><body>';
}

$xname = 'wpTextbox1';
echo '<Form action="'.$this->wiki.'/w/index.php?title='.$name.'&amp;action=submit" METHOD="POST" enctype="multipart/form-data" name="rk" id="editform"><center>
<script language="JavaScript">
function emoticon('.$xname.') {
'.$xname.' = \'\' + '.$xname.' + \'\';
if (document.rk.'.$xname.'.create'.$xname.'Range && document.rk.'.$xname.'.caretPos) {
var caretPos = document.rk.'.$xname.'.caretPos;
caretPos.'.$xname.' = caretPos.'.$xname.'.charAt(caretPos.'.$xname.'.len gth - 1) == \' \' ? '.$xname.' + \' \' : '.$xname.';
document.rk.'.$xname.'.focus();
} else {
document.rk.'.$xname.'.value += '.$xname.';
document.rk.'.$xname.'.focus();
}
}
</script>';

echo '<center><textarea cols="75" rows="30" name="'.$xname.'">'.$ar[2][0].'</textarea><BR>
<input type="button" value="Link to a wiki page" onClick="javascript:emoticon(\'[[wiki_page]]\')">
<input type="button" value="Link" onClick="javascript:emoticon(\'[http://your_url.pl Page Title]\')">
<input type="button" value="Graphic" onClick="javascript:emoticon(\'[[Grafika:filename]]\')">
<input type="button" value="H1 - Big Title" onClick="javascript:emoticon(\'= Title =\')">
<input type="button" value="H2 - Medium Title" onClick="javascript:emoticon(\'== Title ==\')">
<input type="button" value="H3 - Small Title" onClick="javascript:emoticon(\'=== Title ===\')">
<input type="button" value="LI - lists" onClick="javascript:emoticon(\'* Text here\')">
<input type="button" value="LI - numeric lists" onClick="javascript:emoticon(\'# Text here\')">
<input type="button" value="Definition" onClick="javascript:emoticon(\'; Definition name : Description\')">
<input type="button" value="HR - line" onClick="javascript:emoticon(\'----\')"><BR><BR>';

echo '<BR><input tabindex=\'5\' id=\'wpSave\' type=\'submit\' value="Save" name="wpSave" accesskey="s">
<input tabindex=\'6\' id=\'wpPreview\' type=\'submit\' value="Preview" name="wpPreview" accesskey="p">
<input tabindex=\'7\' id=\'wpDiff\' type=\'submit\' value="Preview Changes" name="wpDiff" accesskey="v"></center></form>';
$wynik = ob_get_contents();
ob_end_clean();
return $wynik;
}
else
{
return false;
}
}
}
?>


a que se puede deber este erro, por mas que busco no encuentro
Debe de ser algo que desconosco
  #2 (permalink)  
Antiguo 19/10/2007, 07:49
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: problema con file_get_contents()

El error es claro, la clase esta tratando de leer una url, pero esta esta prohibida por eso te lanza el error, no es de tu clase ni mucho menos, es que la URL que estas tratando de leer necesita algun tipo de autentificacion.

Saludos.
  #3 (permalink)  
Antiguo 19/10/2007, 11:55
 
Fecha de Ingreso: febrero-2007
Mensajes: 103
Antigüedad: 17 años, 2 meses
Puntos: 0
Re: problema con file_get_contents()

Cierto, me lo figuraba, pero entonces como se explica que se
pueda acceder directamente desde la barra de direcciones
poniendo el mismo string que hay entre los parentesis del
file_get_contents(), y ademas que tipo de autentificacion
debe de existir para leer una pagina de la wikipedia que es
totalmente libre.
No lo entiendo
  #4 (permalink)  
Antiguo 19/10/2007, 12:02
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: problema con file_get_contents()

Puede que tengan algun control dependiendo del user agent que envie. Hay muchas formas de denegar o permitir cierto contenido dependiendo de la forma que el cliente lo pida.

Saludos.
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 19:16.