< ? php
include("geoip/geoipregionvars.php"); <--- (you need this snipped for region/states targets, I have one self-wrote for my needs. It works).
include_once("geoip/geoip.inc"); (in the package from MaxMind)
include_once("geoip/geoipcity.inc"); (same as above)
$ip = $_SERVER["REMOTE_ADDR"]; (ip of the visitor)
$gi = geoip_open("geoip/GeoIP.dat",GEOIP_MEMORY_CACHE); (open the GeoIP database)
$gs = geoip_open("geoip/GeoIPCity.dat",GEOIP_MEMORY_CACHE); (open the GeoIPCity database)
$record = geoip_record_by_addr($gs,"$ip"); (this outputs the record by address)
$regcode =$record->region; (this outputs the state/region CODE, ie NJ)
$regname = $GEOIP_REGION_NAME[$record->country_code][$record->region]; (this outputs the region/state name, ie NEW JERSEY)
$countrycode = geoip_country_code_by_addr($gi, "$ip"); (this outputs the country code, ie US)
$countryname = geoip_country_name_by_addr($gi, "$ip"); (and this the country name, ie UNITED STATES)
geoip_close($gi); (close all connection to geoip databases, always!)
geoip_close($gs); (same as above)
?>