Location: PHPKode > scripts > Turnkey Script: What is your IP? > what-is-your-ip/lib/class.hostIp.php
<?php
/**
 * What's your IP?
 * (C) SellTurnkey.com
 */
	require_once dirname (__FILE__) ."/class.http.php";
	
	/**
	 * host ip api wrapper class
	 */
	class hostIp
	{
		//constructor
		function hostIp ()
		{
			
		}
		
		/**
		 * get locations
		 */
		function getLocations ($ip)
		{
			$arrResult = array ();
			$arrResult["Country"] = "";
			$arrResult["City"] = "";
			$arrResult["Longitude"] = "";
			$arrResult["Latitude"] = "";
			
			$httpClient = new http( HTTP_V11, false); 
			$httpClient->host = "api.hostip.info"; 
			
			$url = "/get_html.php?ip=". urlencode ($ip) ."&position=true";
			if ($httpClient->get ($url ) == HTTP_STATUS_OK) 
			{
				$httpResult = $httpClient->get_response_body();
				$httpResult = str_replace ("\r", "", $httpResult);
				$arrHttpResult = explode ("\n", $httpResult);
				foreach ($arrHttpResult as $index => $value)
				{
					$arrValue = explode (": ", $value);
					if ($index == 0 && isset ($arrValue[1]))
						$arrResult["Country"] = $arrValue[1];
					
					if ($index == 1 && isset ($arrValue[1]))
						$arrResult["City"] = $arrValue[1];
					
					if ($index == 2 && isset ($arrValue[1]))
						$arrResult["Latitude"] = $arrValue[1];
						
					if ($index == 3 && isset ($arrValue[1]))
						$arrResult["Longitude"] = $arrValue[1];
				}
			}
			
			return $arrResult;
			
		}
		
		//get flag image
		function getImgFlag ($ip)
		{
			return "http://api.hostip.info/flag.php?ip=". urlencode ($ip);
		}
		
		
		
		
	}	

?>
Return current item: Turnkey Script: What is your IP?