MaxMind GEO IP service and Javascript!

ok so i need to run a script in the head of a website that will perform a certain action depending on the users country…

I’m using www.maxmind.com’s geo ip service and this is the php script i have

<?php 
$license_key = "**********";
$ipaddress = $_SERVER['REMOTE_ADDR'];
$query = "http://geoip3.maxmind.com/b?l=" . $license_key . "&i=" . $ipaddress;
$url = parse_url($query);
$host = $url["host"];
$path = $url["path"] . "?" . $url["query"];
$timeout = 1;
$fp = fsockopen ($host, 80, $errno, $errstr, $timeout)
    or die('Can not open connection to server.');
if ($fp) {
  fputs ($fp, "GET $path HTTP/1.0nHost: " . $host . "nn");
  while (!feof($fp)) {
    $buf .= fgets($fp, 128);
  }
  $lines = explode("n", $buf);
  $data = $lines[count($lines)-1];
  fclose($fp);
} else {
  # enter error handing code here
}
$geo = explode(",",$data);
$country = $geo[0];
$state = $geo[1];
$city = $geo[2];
$lat = $geo[3];
$lon = $geo[4];

if ( $country != "UA" && $country != "RU" && $ipaddress != "**.**.**.**") {
    header('Location: http://www.google.com/');
}
?>

it works great when i test it.. everything is fine.. however, the website i am putting this on uses and i dont have FTP access to the site.. I am however able to add script to the head of the website..

the only issue is that i can only use Javascript, CSS and HTML in the head….

my question is.. is there some sort of Javascript solution that will do what my php script does? even if i have to run the traffic through another site that i DO have FTP access to??

anyone?

fuhhh. how would i accomplish this with jQuery?

just so you guys don’t need to read through the code to figure out whats going on, i bolded the important bit:

<?php 
$license_key = "**********";
$ipaddress = $_SERVER['REMOTE_ADDR'];
$query = "http://geoip3.maxmind.com/b?l=" . $license_key . "&i=" . $ipaddress;
$url = parse_url($query);
$host = $url["host"];
$path = $url["path"] . "?" . $url["query"];
$timeout = 1;
$fp = fsockopen ($host, 80, $errno, $errstr, $timeout)
    or die('Can not open connection to server.');
if ($fp) {
  fputs ($fp, "GET $path HTTP/1.0nHost: " . $host . "nn");
  while (!feof($fp)) {
    $buf .= fgets($fp, 128);
  }
  $lines = explode("n", $buf);
  $data = $lines[count($lines)-1];
  fclose($fp);
} else {
  # enter error handing code here
}
$geo = explode(",",$data);
$country = $geo[0];
$state = $geo[1];
$city = $geo[2];
$lat = $geo[3];
$lon = $geo[4];

if ( $country != "UA" && $country != "RU" && $ipaddress != "**.**.**.**") {
    header('Location: http://www.google.com/');
}
?>

the $country variable is the only one i am concerned with.. i to perform an action (redirect) based on its value..

	function myFunction() {
		$.ajax({
			type: 'GET', //or post, whatever floats your boat
			url: 'URL_HERE',
			data: { 'parameter1': 'value1', 'param2': 'value2', 'etc': 'etc' },
			datatype: "html", //or xml or json - however it comes back to you
			success: function (data) {
				// do stuff, like parsing
				// or call another function that handles the data properly
			},
			error: function () {
				alert('There was a problem retrieving the data, please try again.');
			}
		});
	}