Subscribe via RSS

PHP Geo IP Address Lookup

Today I searched on how to get the city of a user based on their ip address. I was looking to do this using PHP and preferably for free. There was quiet a bit out there that had a free database you could download to cross reference that would return the country. However, we wanted to be able to get the city and state as well. After quiet a bit of googling, I came across a free API from ipgp.net. They allow you to post the ip to a URL and they return an XML packet with the county, a path to the image of the country’s flag, city, state, isp, latitude, and longitude. They have an example on how to do this on their page. We created our own class below for your use that is a little cleaner. It can be included in your php scripts and you don’t have to worry about downloading anything into MySQL.

	/*
		Provided by http://www.todayisearched.com
	*/
	class GeoIP {

		/*
			Returns all possible Geo Ip information in an associative array.  The following pieces of information
			are returned:
			IP - IP ADDRESS LOOKED UP
			CODE - COUNTRY CODE
			COUNTY - COUNTRY NAME
			FLAG - PATH TO IMAGE OF THE COUNTRY'S FLAG
			CITY - CITY NAME
			REGION - STATE NAME
			ISP - ISP NAME
			LAT - LATITUDE CORDINATE
			LNG - LONGITUDE CORDINATE

			USAGE:
			$ipinfo = GeoIP :: getGeoArray('xxx.xxx.xxx.xxx');
			echo $ipinfo['CITY'] . ', ' . $ipinfo['STATE'];
		*/
		public static function getGeoArray($ip) {
			$file = "http://www.ipgp.net/api/xml/". $ip;

			$xml_parser = xml_parser_create();
			$fp = fopen($file, "r");
			$data = fread($fp, 80000);
			xml_parse_into_struct($xml_parser, $data, $vals);
			$iplookup = array();
			foreach ($vals as $v) {
				if (isset($v['tag']) && isset($v['value'])) {
					$iplookup[$v['tag']] = $v['value'];
				}
			}
			xml_parser_free($xml_parser);
			fclose($fp);

			return $iplookup;
		}

		//shortcut to get the city name
		public static function getCity($ip) {
			$a =  self :: getGeoArray($ip);
			return $a['CITY'];
		}

		//shortcut to get the state name
		public static function getState($ip) {
			$a =  self :: getGeoArray($ip);
			return $a['REGION'];
		}

	}

Follow these steps to implement the above script:

  1. Copy the script above and save it into a php file on your server
  2. Add include_once(‘Path To The PHP File Saved On #1′);
  3. Use the code snippet below in your php to obtain geoip information.
      include_once "geoip.php";
      $ipinfo = GeoIP :: getGeoArray($_SERVER['REMOTE_ADDR']);
      echo 'Hello, Your City And State Is ' . $ipinfo['CITY'] . ', ' . $ipinfo['REGION'];

Thanks http://www.ipgp.net for providing this invaluable service!

Migrating ODBC Data Sources From XP To Windows 7

Today I searched how to migrate ODBC data sources from Windows XP to Windows 7. I have built up quiet the list of data sources over the years and was dreading having to key in each one after setting up Windows 7. I found a free ODBC tool called DTM ODBC Manager. It allows for backup of ODBC data sources. This backup can then be imported back into another windows installation via their software.

Migrate ODBC Data Sources

DTM ODBC Manager Interface

Follow these simple steps to backup your ODBC data sources:

  1. Download and install the DTM ODBC Manager
  2. Open up the DTM ODBC Manager and select the System and User DSN’s to backup.  They are all checked by default.
  3. Click the arrow next to the export button at the top and select “export selected”.
  4. Give your backup file a name when prompted.

Follow these simple steps to restore your ODBC data sources:

  1. Copy the backup file created above to the machine it is going to be restored to.
  2. Install the DTM ODBC Manager on the machine the data sources are being restored to.
  3. Open up the DTM ODBC Manager
  4. Click the import button and browse to the backup file.

All your data sources should now be imported on the new computer or clean Windows install depending on what you are doing.  You will still have to install the odbc data source drivers that you will be using.  Your data sources will not work correctly until the database driver is installed on the new system.  Hats off to the DTM people for making this easy to use product available for free.

How to add brushes in gimp 2.6

Today I searched How to add brushes in gimp 2.6 and found this sweet video with rock en music that guided me along to install brushes in gimp 2.6. It is kinda hard to read the text so here are the steps:

  1. Download the brush that you want to install and make sure you have a zip program installed to extract them.
  2. Read the rest of this entry »