I'm an IPB developer, i recently created a modification of IPB to show Visitors/Guests Country Flags (Doesnt connect to databse) and Members Current Country/City/Country code (which connects to database and insert/update members tables with the previous returns i mentioned.
So anyways my issue is when hostip.info is down my site (and of course everyone that uses my script) goes down as well!
here are the codes i'm using
- Code: Select all
//-----------------------------------------
// -SRD23- Flag IP
//-----------------------------------------
$DB->simple_construct( array(
'select' => 'cc,country,city',
'from' => 'members',
'where' => 'id ='.$member['id']
) );
$this->ipsclass->DB->simple_exec();
$memip = $this->ipsclass->DB->fetch_row();
#get ip
if (!empty($_SERVER['HTTP_CLIENT_IP']))
//check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
//to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
//verify the IP address for the
ip2long($ip)== -1 || ip2long($ip) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
$ipDetail=array();
//get the XML result from hostip.info
$xml = file_get_contents("http://api.hostip.info/?ip=".$ip); //Here were i have the problem
preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match);
$ipDetail['city']=$match[2];
preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches);
$ipDetail['country']=$matches[1];
preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match);
$ipDetail['country_code']=$cc_match[1];
//return the array containing city, country and country code
$country = $ipDetail['country'];
$city = $ipDetail['city'];
$country_code = str_replace( "XX" , "" , $ipDetail['country_code']); //remove XX if return is unkown
#Check if we have new info for registered members
if (($member['id']) AND ($member['cc'] != $country_code OR $member['country'] != $country OR $member['city'] != $city))
{
#update to databse if new info found
$DB->do_update( 'members', array(
'cc' => $country_code,
'country' => $country,
'city' => $city,
), 'id ='.$member['id']);
}
//set Our vars
$members_flag = "<b>Current Country:</b> {$memip['country']} <img src='flags/{$memip['cc']}1.gif' alt='{$memip['country']}' /> <b>Current City:</b> {$memip['city']}";
$guests_flag = "<b>Current Country:</b> {$country} <img src='flags/{$country_code}1.gif' alt='{$country}' /> <b>Current City:</b> {$city}";
//Display
if(empty($member['id'])) {echo $guests_flag;}else{echo $members_flag;}
Now is there is a way to limit the time out of the get_file_content? because as i said earlier when you guys are down all our sites goes down as well!!!
Thanks in advanced
Sacred [at] IBMafia.com