Help resolving this "URL file-access" problem

apps

#1

Hi, i’ve got this code:


<? # ID de tu sitio # Reemplazar en la linea 119 "279170" por tu site id //Variable de URL as_categ_id $id_categ=$HTTP_GET_VARS[as_categ_id]; if ($HTTP_GET_VARS[as_categ_id]=="") { $id_categ="1000"; } //Variable de URL buscar $buscar=$HTTP_GET_VARS[buscar]; //Variable de URL pais (MLA,MLB,etc) $pais=strtoupper($HTTP_GET_VARS[pais]); //Elije el dominio de MercadoLibre switch ($pais) { case "MLA": $dominio="www.mercadolibre.com.ar"; break; default: $dominio="www.mercadolibre.com.ar"; }?> Articulos en Mercadolibre
RM Shop
MercadoLibre.com.ar
Las mejores ofertas!
<?php

$insideitem = false;
$item = array();
$tag = “”;
$title = “”;
$description = “”;
$link = “”;
$price = “”;
$image="";
$currency= “”;

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link, $price, $image, $currency, $item;
if ($insideitem) {
$tag = $name;
} elseif ($name == “ITEM”) {
$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link, $price, $image, $currency, $item, $attrs;
if ($name == “ITEM”) {
echo “

”;
echo “<td width=“40”><img src=”".$image."" height=“35”>";
echo “";
echo “”;
echo “”;
echo “<td height=“1” colspan=“2” bgcolor=”#ffffff">";
echo “”;
$title = “”;
$description = “”;
$link = “”;
$price = “”;
$item = “”;
$image = “”;
$currency = “”;
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link, $price, $image, $currency, $item, $attrs;
if ($insideitem) {
switch ($tag) {
case “ITEM”:
$id .= $item[‘ID’];
break;
case “TITLE”:
$title .= $data;
break;
case “DESCRIPTION”:
$description .= $data;
break;
case “LINK”:
$link .= str_replace(“XXX”,“5344039”,$data);
break;
case “PRICE”:
$price .= $data;
break;
case “IMAGE_URL”:
$image .= $data;
break;
case “CURRENCY”:
$currency .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, “startElement”, “endElement”);
xml_set_character_data_handler($xml_parser, “characterData”);
$fp = fopen(“http://”.$dominio."/jm/searchXml?as_categ_id=".$id_categ."&as_word=".$buscar."&as_order_id=MAS_OFERTADOS&as_filtro_id=PRECIO_FIJO&as_display_type=G",“r”)
or die(“Error reading data.”);
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf(“XML error: %s at line %d”,
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

<a href=”".$link."" target="_blank">".$title."<font class=“precio”>".$currency.$price."
-----------------------------------------------------------------

And i get this error:
Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/.snapple/xxx/xxx.com/folder/subfolder/xml_listado.php on line 137

How can i solve this??

Please help me as i dont know anything about PHP and i will thank you all my life :smiley:

bye :wink:


#2

fopen is disabled for security reasons, but you can use cURL:

http://wiki.dreamhost.com/CURL

-Scott


#3

the thing is that i dont know how to use it,…

i was looking for someone to help me !

bye :wink:


#4

Try:

$fp = curl_init();
curl_setopt($ch, CURLOPT_URL, “http://”.$dominio."/jm/searchXml?as_categ_id=".$id_categ."&as_word=".$buscar."&as_order_id=MAS_OFERTADOS&as_filtro_id=PRECIO_FIJO&as_display_type=G",“r”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);

I’m not sure what the “r” does at the end of your URL, but experiment with the above code. Hopefully it’ll get you close.

-Scott


#5

i thank you a lot… first for taking your time to read my post…

but, could you put the hole code with your correction?, as i dont know from which line should i delete and correct the script.

Bye :wink:


#6

Sorry, you should be replacing:

$fp = fopen(“http://”.$dominio."/jm/searchXml?as_categ_id=".$id_categ."&as_word=".$buscar."&as_order_id=MAS_OFERTADOS&as_filtro_id=PRECIO_FIJO&as_display_type=G",“r”)

It’s near the bottom of your code. Keep the:

or die(“Error reading data.”);

-Scott


#7

You should also be replacing all instances of $HTTP_GET_VARS with $_GET, since the former is deprecated.

si-blog
Max discount on any plan with promocode SCJESSEYTOTAL


#8

I get:
when i visit:
http://www.riveresmundial.com.ar/es/shop/xml_listado.php?as_categ_id=1286&buscar=river&pais=MLA

Asi “river” is the word to search and “1286” teh category to search in on these script that loads PRODUCTS from www.mercadolibre.com.ar (its like Ebay)


Warning: Wrong parameter count for curl_setopt() in /home/.snapple/riveresm/riveresmundial.com.ar/es/shop/xml_listado.php on line 114

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/.snapple/riveresm/riveresmundial.com.ar/es/shop/xml_listado.php on line 115

Warning: curl_exec(): supplied argument is not a valid cURL handle resource in /home/.snapple/riveresm/riveresmundial.com.ar/es/shop/xml_listado.php on line 116

Warning: curl_close(): supplied argument is not a valid cURL handle resource in /home/.snapple/riveresm/riveresmundial.com.ar/es/shop/xml_listado.php on line 117

Warning: fread(): supplied resource is not a valid stream resource in /home/.snapple/riveresm/riveresmundial.com.ar/es/shop/xml_listado.php on line 118

Warning: fclose(): supplied resource is not a valid stream resource in /home/.snapple/riveresm/riveresmundial.com.ar/es/shop/xml_listado.php on line 123

The code now its:


<? # ID de tu sitio # Reemplazar en la linea 119 "279170" por tu site id //Variable de URL as_categ_id $id_categ=$_GET[as_categ_id]; if ($_GET[as_categ_id]=="") { $id_categ="1000"; } //Variable de URL buscar $buscar=$_GET[buscar]; //Variable de URL pais (MLA,MLB,etc) $pais=strtoupper($_GET[pais]); //Elije el dominio de MercadoLibre switch ($pais) { case "MLA": $dominio="www.mercadolibre.com.ar"; break; default: $dominio="www.mercadolibre.com.ar"; }?> Articulos en Mercadolibre
RM Shop
MercadoLibre.com.ar
Las mejores ofertas!
<?php

$insideitem = false;
$item = array();
$tag = “”;
$title = “”;
$description = “”;
$link = “”;
$price = “”;
$image="";
$currency= “”;

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link, $price, $image, $currency, $item;
if ($insideitem) {
$tag = $name;
} elseif ($name == “ITEM”) {
$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link, $price, $image, $currency, $item, $attrs;
if ($name == “ITEM”) {
echo “

”;
echo “<td width=“40”><img src=”".$image."" height=“35”>";
echo “";
echo “”;
echo “”;
echo “<td height=“1” colspan=“2” bgcolor=”#ffffff">";
echo “”;
$title = “”;
$description = “”;
$link = “”;
$price = “”;
$item = “”;
$image = “”;
$currency = “”;
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link, $price, $image, $currency, $item, $attrs;
if ($insideitem) {
switch ($tag) {
case “ITEM”:
$id .= $item[‘ID’];
break;
case “TITLE”:
$title .= $data;
break;
case “DESCRIPTION”:
$description .= $data;
break;
case “LINK”:
$link .= str_replace(“XXX”,“5344039”,$data);
break;
case “PRICE”:
$price .= $data;
break;
case “IMAGE_URL”:
$image .= $data;
break;
case “CURRENCY”:
$currency .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, “startElement”, “endElement”);
xml_set_character_data_handler($xml_parser, “characterData”);
$fp = curl_init();
curl_setopt($ch, CURLOPT_URL, “http://”.$dominio."/jm/searchXml?as_categ_id=".$id_categ."&as_word=".$buscar."&as_order_id=MAS_OFERTADOS&as_filtro_id=PRECIO_FIJO&as_display_type=G",“r”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf(“XML error: %s at line %d”,
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

<a href=”".$link."" target="_blank">".$title."<font class=“precio”>".$currency.$price."
---------------------------------------------------------------------

Bye :wink: