DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Recupera Datos Del Visitante

10.03.2007
| 2910 views |
  • submit to reddit
        
	function getLocation( $ip ) {
		
		static $location = array();
		
		if( !isset( $location[$ip] ) ) {
			$url = "http://www.hostip.info/api/get.html?ip=" . $ip . "&position=true&raandom=" . rand(0,500);
			/* cURL */
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$data = curl_exec($ch);

			if ( curl_errno( $ch ) ) {
				print "Error: ".curl_error($ch);
			} else {
				curl_close($ch);
				$lines = split ("\n", $data);
				foreach($lines as $l):
					$prop = split(':',$l);
					$location[$ip][trim($prop[0])] = addslashes(trim($prop[1]));
				endforeach;
		   }
			
		}
		return $location[$ip];
	}