FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


fopen in server frihost?





rafael2112
I have a script , which has the function fopen,Localhost more runs on the server fhihost no!!!

This function is disabled on the server frihost?

To this page in Portuguese, Just click "BUSCAR VEICULOS" or "BUSCAR PRODUTOS" , will notice the error...
http://autoxbr.frihost.net/shopping/
Star Wars Fanatic
Yes, fopen is disabled, see this post for more info (http://www.frihost.com/users/Bondings/blog/vp-81287.html).

You can, (to quote Bondings)
Bondings wrote:
The solution is to use something like curl for opening url files.

Something like:
Code:
<?php
/*
   * @return string
   * @param string $url
   * @desc Return string content from a remote file
   * @author Luiz Miguel Axcar (lmaxcar@yahoo.com.br)
*/

function get_content($url)
{
    $ch = curl_init();

    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);

    ob_start();

    curl_exec ($ch);
    curl_close ($ch);
    $string = ob_get_contents();

    ob_end_clean();
   
    return $string;   
}

#usage:
$content = get_content ("http://www.php.net");
var_dump ($content);
?>
rafael2112
Could help me, adapt these two code in the script to function CURL

Code:
<?


$usuario = $username;
$clave = $senha;


$categ_id=( isset($HTTP_POST_VARS['vx_tipo']) ) ? $HTTP_POST_VARS['vx_tipo'] : $HTTP_GET_VARS[vx_tipo];
$marca=( isset($HTTP_POST_VARS['vx_marca']) ) ? $HTTP_POST_VARS['vx_marca'] : $HTTP_GET_VARS[vx_marca];
$modelo=( isset($HTTP_POST_VARS['vx_modelo']) ) ? $HTTP_POST_VARS['vx_modelo'] : $HTTP_GET_VARS[vx_modelo];
$desde=( isset($HTTP_POST_VARS['desde']) ) ? $HTTP_POST_VARS['desde'] : $HTTP_GET_VARS[desde];
$ate=( isset($HTTP_POST_VARS['ate']) ) ? $HTTP_POST_VARS['ate'] : $HTTP_GET_VARS[ate];

$siteID= $seu_id;
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><? echo $marca." ".$modelo; ?> - Loja Virtual</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="" />
<meta name="keywords" content="" />

<link href="estilo.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="ajax.js"></script>

</head>

<body>
<div id="principal">

   <div id="barra_top"><script language="javascript" type="text/javascript">ajaxpage('barra_top.php', 'barra_top');</script></div>

   <div>&nbsp;</div>

   <div id="conteudo">
      <div id="menu">




      </div>


<!-- Aqui inicia o conteúdo -->

      <div id="conteudo_in">




<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="95%">
    <tr>
      <td width="100%">
        <div align="left">
          <table border="0" cellpadding="0" cellspacing="0" width="100%" >
            <tr>
              <td width="46%" bgcolor="#f9f9f9" colspan="2" style="border-left:1px solid #cccccc;border-top:1px solid #cccccc;border-bottom:1px solid #cccccc; ">&nbsp;</td>
              <td width="18%" bgcolor="#f9f9f9" align="center" style="border-top:1px solid #cccccc;border-bottom:1px solid #cccccc;"><font color="#336699" size="1" face="Arial">Ano</font>&nbsp;&nbsp;&nbsp;&nbsp;</td>
              <td width="18%" bgcolor="#f9f9f9" align="center" style="border-right:1px solid #cccccc;border-top:1px solid #cccccc;border-bottom:1px solid #cccccc;"><font color="#336699" size="1" face="Arial">Preço</font></td>
            </tr>
      <?php

$insideitem = false;
$item = array();
$tag = "";
$title = "";
$link = "";
$model = "";
$year = "";
$km = "";
$price = "";
$image="";
$currency= "";
$corfundo="#f7f7f7";
$trocacor = false;

function startElement($parser, $name, $attrs) {
   global $insideitem, $tag, $title, $link, $model, $year, $km, $price, $image, $currency, $item;
   if ($insideitem) {
      $tag = $name;
   } elseif ($name == "ITEM") {
      $insideitem = true;
   }
}

function endElement($parser, $name) {
   global $insideitem, $tag, $title, $link, $model, $year, $km, $price, $image, $currency, $item, $attrs, $corfundo, $trocacor;
   if ($name == "ITEM") {
               echo "<tr>";
               echo "<td width=\"10%\" bgcolor=\"".$corfundo."\">";
               echo "<p align=\"left\"><a href=\"".$link."\" target=\"_blank\"><img height=\"90\" hspace=\"0\" src=\"".$image."\" width=\"90\" align=\"absMiddle\" border=\"0\"></a></td>";
               echo "<td width=\"36%\" bgcolor=\"".$corfundo."\"><a href=\"".$link."\" target=\"_blank\" style=\"font-size:10px;color:#777777;\"><b>".$model."</b></a>";
               echo "<p><font color=\"#777777\" face=\"Arial\" size=\"2\"><a href=\"".$link."\" target=\"_blank\">".utf8_decode($title)."</a></font></td>";
               echo "<td width=\"18%\" bgcolor=\"".$corfundo."\" valign=\"middle\" align=\"center\"><font size=\"2\" face=\"Arial\" color=\"#777777\">".$year."</a></font></td>";
               echo "<td width=\"18%\" bgcolor=\"".$corfundo."\" valign=\"middle\" align=\"center\"><font size=\"2\" face=\"Arial\" color=\"#777777\">".$currency." ".$price."</font></td>";
               echo "</tr>";
      $title = "";
      $link = "";
      $model = "";
      $year = "";
      $km = "";
      $price = "";
      $item = "";
      $image = "";
      $currency = "";
      $insideitem = false;
      if ($trocacor) {
         $corfundo = "#f7f7f7";
         $trocacor = false;
      } else {
         $corfundo = "#FFFFFF";
         $trocacor = true;
      }
   }
}

function characterData($parser, $data) {
   global $insideitem, $tag, $title, $link, $model, $year, $km, $price, $image, $currency, $item, $attrs, $siteID;
   if ($insideitem) {
   switch ($tag) {
      case "ITEM":
      $id .= $item['ID'];
      break;
      case "TITLE":
      $title .= utf8_encode($data);
      break;
      case "LINK":
      $link .= str_replace("XXX",$siteID,$data);
      break;
      case "MODEL":
      $model .= utf8_decode($data);
      break;
      case "YEAR":
      $year .= $data;
      break;
      case "KM":
      $km .= $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");

if (function_exists('curl_init')) {

$url = "http://www.mercadolivre.com.br/jm/searchXml?as_categ_id=".$categ_id."&marca=".$marca."&modelo=".$modelo."&as_year_min=".$desde."&as_year_max=".$ate."&user=".$usuario."&pwd=".$clave."";
// Using curl
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);

} else {

$fp = fopen("http://www.mercadolivre.com.br/jm/searchXml?as_categ_id=".$categ_id."&marca=".$marca."&modelo=".$modelo."&as_year_min=".$desde."&as_year_max=".$ate."&user=".$usuario."&pwd=".$clave."","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_parse($xml_parser, $data) or die("");
xml_parser_free($xml_parser);

?>

          </table>
        </div>
        <p><br>
      </td>
    </tr>
  </table>
  </center>
</div>

<!-- Término de conteúdo -->
      </div>
   </div>
   

   <div id="barra_bottom"><script language="javascript" type="text/javascript">ajaxpage('barra_bottom.php', 'barra_bottom');</script></div>

</div>


</body>
</html>



Code:

<?

$id_categ=$HTTP_GET_VARS[categoria];
$preco=$HTTP_GET_VARS[preco];
$max=$HTTP_GET_VARS[max];
$siteID="343425";


$dominio="www.mercadolivre.com.br";
?>
<html>
<head>
<style type="text/css">
.precio {
font-family: Tahoma, Helvetica, sans-serif;
font-size: 10px;
color: #CC0000;
</style>
</head>
<body topmargin="0" leftmargin="0" >
<dl>
<table width="395" height="50" order="0" cellpadding="0" cellspacing="0" bgcolor="#f0f0f0" align="center"><tr>
<?php

$insideitem = false;
$item = array();
$tag = "";
$title = "";
$link = "";
$price = "";
$image="";
$currency= "";
$count = 1;

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

function endElement($parser, $name) {
global $insideitem, $tag, $title, $link, $price, $image, $currency, $item, $attrs, $count, $max;
if ($name == "ITEM") {
echo "<td align=\"center\" valign=\"middle\" style=\"padding:1px\">";
echo "<img width=\"80\" height=\"80\" src=\"".$image."\" align=\"center\" valign=\"middle\" >";
echo "<div style=\"word-wrap: break-word; width:119px\"><a href=\"".$link."\" target=\"_blank\">".$title."</a><br><img height=\"3\" src=\"spacer.gif\" align=\"center\" valign=\"middle\" ><br>";
echo "<font class=\"precio\">por apenas <b>".$currency.$price."<br></b></font></div></td></strong>";
$title = "";
$link = "";
$price = "";
$item = "";
$image = "";
$currency = "";
$insideitem = false;
$count = $count + 1;
if ($count == 4)
{
echo "</tr><tr><td height=\"15px\"> </td></tr><tr>";
$count = 1;
}
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $link, $price, $image, $currency, $item, $attrs, $siteID;
if ($insideitem) {
switch ($tag) {
case "ITEM":
$id .= $item['ID'];
break;
case "TITLE":
$title .= $data;
break;
case "LINK":
$link .= str_replace("XXX",$siteID,$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_price_min=".$preco."&as_order_id=MAS_OFERTADOS&as_filtro_id=PRECIO_FIJO&as_display_type=G&noQCat=Y&as_qshow=".$max."","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);

?>
</dl>
</table>
</body>


Thanks for attention!
manav
curl is a nice solution

for examples goto phpian.com

u'll find some real world curl usage examples...
rafael2112
I have a code, that has changed fopen, to curl
Most did not understand Modify code

Fopen

Quote:
<?
# ID de tu sitio
# Reemplazar en la linea 102 "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;
case "MLB":
$dominio="www.mercadolivre.com.br";
break;
case "MLM":
$dominio="www.mercadolibre.com.mx";
break;
case "MLC":
$dominio="www.mercadolibre.cl";
break;
case "MLV":
$dominio="www.mercadolibre.com.ve";
break;
case "MCO":
$dominio="www.mercadolibre.com.co";
break;
case "MLU":
$dominio="www.mercadolibre.com.uy";
break;
case "MEC":
$dominio="www.mercadolibre.com.ec";
break;
case "MLP":
$dominio="www.mercadolibre.com.pe";
break;
default:
$dominio="www.mercadolibre.com.ar";
}?>
<html>
<head>
<title>Articulos en Mercadolibre</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<dl>
<table width="468" height="60" border="0" cellpadding="0" cellspacing="0">
<tr>
<?php

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

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

function endElement($parser, $name) {
global $insideitem, $tag, $title, $link, $price, $image, $currency, $item, $attrs;
if ($name == "ITEM") {
echo "<td width=\"60\">";
echo "<img src=\"".$image."\" height=\"60\"></td>";
echo "<td width=\"147\"><a href=\"".$link."\" target=\"_blank\">".$title."</a><br>";
echo "<font class=\"precio\">".$currency.$price."</font></td>";
$title = "";
$link = "";
$price = "";
$item = "";
$image = "";
$currency = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $link, $price, $image, $currency, $item, $attrs;
if ($insideitem) {
switch ($tag) {
case "ITEM":
$id .= $item['ID'];
break;
case "TITLE":
$title .= $data;
break;
case "LINK":
$link .= str_replace("XXX","279170",$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&noQCat=Y&as_qshow=2","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);

?>
<td width="54" bgcolor="#FEE600"> <div align="center"><img src="http://www.mercadolibre.com.ar/org-img/popups/pirateria/logo_<? if ($pais=="MLB") { echo "mlb"; } else { echo "ml"; }?>.gif" width="50" height="35"></div></td>
</tr>
</table>
</dl>
</body>
</html>


CURL

Quote:
<?
# ID de tu sitio
# Reemplazar en la linea 102 “333296″ por tu site id

$cats = array(0 => 1000, 1 => 1776, 2 => 1000, 3 => 1132,
4 => 1841, 5 => 1743, 6 => 1051, 7 => 1798,
8 => 1835, 9 => 3398, 10 => 1039, 11 => 1276,
12 => 1292, 13 => 1743, 14 => 1176, 15 => 1144,
16 => 1144, 17 => 1648, 18 => 1182, 19 => 3398,
20 => 1039);
$i = rand(0, 20);
$id_categ=$cats[$i];

//Variable de URL buscar
$buscar=$HTTP_GET_VARS[buscar];
//Variable de URL pais (MLA,MLB,etc)
$pais=“MLB”;

//Elije el dominio de MercadoLibre
switch ($pais) {
case “MLA”:
$dominio=“www.mercadolibre.com.ar”;
break;
case “MLB”:
$dominio=“www.mercadolivre.com.br”;
break;
case “MLM”:
$dominio=“www.mercadolibre.com.mx”;
break;
case “MLC”:
$dominio=“www.mercadolibre.cl”;
break;
case “MLV”:
$dominio=“www.mercadolibre.com.ve”;
break;
case “MCO”:
$dominio=“www.mercadolibre.com.co”;
break;
case “MLU”:
$dominio=“www.mercadolibre.com.uy”;
break;
case “MEC”:
$dominio=“www.mercadolibre.com.ec”;
break;
case “MLP”:
$dominio=“www.mercadolibre.com.pe”;
break;
default:
$dominio=“www.mercadolibre.com.ar”;
}?>
<html>
<head>
<title>Articulos en Mercadolibre</title>
<link href=“styles.css” rel=“stylesheet” type=“text/css”>
</head>
<body>
<table width=“468″ height=“60″ border=“0″ cellpadding=“0″ cellspacing=“0″>
<tr>
<?php

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

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

function endElement($parser, $name) {
global $insideitem, $tag, $title, $link, $price, $image, $currency, $item, $attrs;
if ($name == “ITEM”) {
echo “<td width=”60”>”;
echo “<img src=”“.$image.“” height=”60”></td>”;
echo “<td width=”147” bgcolor=’#FFFFFF’><a href=”“.$link.“” target=”_blank”>”.
htmlentities($title).“</a><br>”;
echo “<font class=”precio”>”.$currency.$price.“</font></td>”;
$title = “”;
$link = “”;
$price = “”;
$item = “”;
$image = “”;
$currency = “”;
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $link, $price, $image, $currency, $item, $attrs;
if ($insideitem) {
switch ($tag) {
case “ITEM”:
$id .= $item[‘ID’];
break;
case “TITLE”:
$title .= $data;
break;
case “LINK”:
$link .= str_replace(“XXX”,“333296″,$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”);
$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”.
“&noQCat=Y&as_qshow=2″,“r”)

$ch = curl_init(); // inicializa um controlador
$timeout = 5; // define um timeout - 5 é o que uso sempre
curl_setopt ($ch, CURLOPT_URL, $url); // $url é a URL a ser aberta
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch); // salva o resultado em $res
curl_close($ch); // fecha o controlador, para economizar memória

xml_parse($xml_parser, $data) 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);

?>
<td width=“54″ bgcolor=“#FEE600″>
<div align=“center”>
<img src=“http://www.mercadolibre.com.ar/org-img/popups/pirateria/logo_<?
if ($pais==“MLB”) {
echo “mlb”; }
else {
echo “ml”; }?>.gif” width=“50″ height=“35″>
</div>
</td>
</tr>
</table>
</body>
</html>


I am grateful for the help!
Related topics
I Have a question . Is it the server support Chinese?
Game Server For Frihost?_? Lol..
same problem over here...
Database Problem
Best Blogging software
Frihost server banned by aol mail because it spams?????
[DESIGNER] - Como posso criar uma página de upload??
Server?? Frihost??
How to begin with hosting my own Domain Name?
Which FAST Server
How to install FreeType on frihost server?
Frihost Down?
PHP e XML
Server 4 is down?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.