![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
17/02/2010, 07:33
|
![Avatar de humanista](http://static.forosdelweb.com/customavatars/avatar97313_3.gif) | | | Fecha de Ingreso: abril-2005
Mensajes: 878
Antigüedad: 19 años, 9 meses Puntos: 15 | |
Respuesta: variables dentro de clases disculpad por la tardanza, aquí tenéis los datos:
class CountryFromIP
{ private $CountryIPDatabase = 'compartido/ip-to-country.csv';
private $ip = '';
/**
* Function to validate IP
*
* @param $ip - string
*
* @return boolean
*/
public function ValdateIP($ip)
{
$ipArray = explode(',',$ip);
if(count($ipArray) != 4)
{
//echo "<font color='red' size='3'> <b>ERROR: </b> Invalid IP</font>";
return false;
}
else
{
return true;
}
}
/**
* Function to return Country name from the IPDatabase
*
* @param $ip string
*
* @return string - name of the country, false otherwise
*/
public function GetCountryName($ip)
{
$this->ip = $ip;
$ip = sprintf("%u", ip2long($ip));
$csvArray = file($this->CountryIPDatabase);
for($i=0; $i<count($csvArray); $i++)
{
$setCsv = str_replace("\"", "", $csvArray[$i]);
$arrayOfLine = explode(',', $setCsv);
if($ip >= $arrayOfLine[0] && $ip <= $arrayOfLine[1] )
{
return $youridcountryname = $arrayOfLine[2];
}
else
{
//return $youridcountryname = "US";
}
}
return false;
}
}
$ip = $_SERVER["REMOTE_ADDR"];
$object = new CountryFromIP();
$youridcountryname = $object->GetCountryName($ip);
esta línea es la culpable del error: private $CountryIPDatabase = 'compartido/ip-to-country.csv';
pq a veces llamo a esta función (q está en la carpeta compartido) desde la raíz o desde otra carpeta, por lo que primero tengo una variable $path q indica si estamos en la raíz o debemos subir un nivel (../).
la idea es q cuando se llame a está función (q está en un fichero .php) se la pueda llamar indicándole el $path.
este es el error q me da cuando lo llamo desde una carpeta q no es la raíz:
Warning: file(compartido/ip-to-country.csv) [function.file]: failed to open stream: No such file or directory in /home/virtual/miweb.com/compartido/index.php on line 345 |