Jump to content

get geo location via ip address error in class


gabrielkolbe

Recommended Posts

Hi, i am not too familiar with oop, and have would really like to use this class where I get the geo location from a user via the ip address. I get this error because the script is written for php5 and I need to convert it to PHP4. I changed ' Private' for ' Var'  which helps , what do I change ' Public' to ?

 

 

Here's the class.....
<?Php
/**
* This class generates the country name and its flag from its IP address
*
*
* @author Rochak Chauhan
*/

class CountryFromIP {

 private $CountryIPDatabase = 'CountryIPDatabase.txt';
 private $ip = '';

/**
 * Function to validate IP ( please modify it according to your needs)
 *
 * @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++) {
		$arrayOfLine = explode(',', $csvArray[$i]);
		if($ip >= $arrayOfLine[0] && $ip <= $arrayOfLine[1] ) {
			return $countryName = $arrayOfLine[2];
		}
	}
	return false;
}

/**
 *  Function to return local path to Country's flag
 *
 * @param $ip - string
 *
 * @return string - local path to flag image
 */
public function ReturnFlagPath() {

	if($countryName = trim(ucwords(strtolower($this->GetCountryName($this->ip))) )) {
                        $countryName = str_replace(' ','%20',$countryName);
		return "flag/$countryName.gif";
	}
	else {
	    return false;
	}
}

}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.