Tenias varios errores
Código PHP:
<html>
<body>
<?php
/**
* This class generates the country name and its flag from its IP address
*
*
* @author Rochak Chauhan
*/
$CountryIPDatabase = 'CountryIPDatabase.txt';
$ip = '';
/**
* Function to validate IP ( please modify it according to your needs)
*
* @param $ip - string
*
* @return boolean
*/
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;
}//Fin del if
}//Fin del function ValdateIP($ip)
/**
* Function to return Country name from the IPDatabase
*
* @param $ip string
*
* @return string - name of the country, false otherwise
*/
function GetCountryName($ip) {
global $CountryIPDatabase;
$ip = sprintf("%u", ip2long($ip));
$csvArray = file($CountryIPDatabase);
for($i=0; $i<count($csvArray); $i++) {
$arrayOfLine = explode(',', $csvArray[$i]);
if($ip >= $arrayOfLine[0] && $ip <= $arrayOfLine[1] ) {
return $countryName = $arrayOfLine[4];
}//Fin del if
}//Fin del for
return false;
}//Fin del function GetCountryName($ip)
/**
* Function to return local path to Country's flag
*
* @param $ip - string
*
* @return string - local path to flag image
*/
function ReturnFlagPath($ip){
$countryName = trim(ucwords(strtolower(GetCountryName($ip))));
if(!empty($countryName)){
$countryName = str_ireplace('%20',' ',$countryName);
return "flag/$countryName.gif";
}else{
return false;
}//Fin del else
}//Fin del function ReturnFlagPath()
$ip = $_SERVER["REMOTE_ADDR"];
$countryName = GetCountryName($ip);
$flagPath = ReturnFlagPath($ip);
echo "<BR> <B>País: </B>".$countryName;
echo "<BR> <B>Bandera: </B> <img src='".$flagPath."' border='0'>";
?>
</body>
</html>
1. Acuerdate siempre escribir entre
comillas las direciones src. Por que habran direcciones con espacios en blanco.
2. No le dijiste de donde sacas el $ip en la funcion de
ReturnFlagPath por eso le añadi el parametro dentro de los parentesis.
3. Saque de la condicion
IF lo que tenias declarado y lo declare arriba, luego verifico si esta vacio o no.
4. el
str_replace lo cambie a
str_ireplace (es mas bien preferencia en este caso) y la forma como se debe llamar es
str_ireplace("buscar","reemplazar","sujeto"), por lo tanto busco los %20 y los reemplazo por espacio en blanco. Tu lo tenias al revés.