I buy GeoIP Web Services to get the client country from there IP’s for my database and they give me a php code to get response from there API to tell me witch country that IP from , here is the code they give it to me:
$query = "http://geoip.maxmind.com/f?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.0\nHost: " . $host . "\n\n");
while (!feof($fp)) {
$buf .= fgets($fp, 128);
}
$lines = explode("\n", $buf);
$data = $lines[count($lines)-1];
fclose($fp);
} else {
# enter error handing code here
}
echo $data;
I get the $data value that told me where the $ipaddress from …… but I get get an error: Undefined variable $buf ?
Add
on top of your code