Journal » Post
|
|
Lack of better things to do I decided to update my guestbook by adding a simple feature which indicates from what country the poster is from. Inspired by an online tracking site I used to maintain, I researched a way to do it in a much easier and quicker fashion. First up, I get an ip range list which is offered for free by some sites, I get mine from MaxMind. They update this list once a month for the free version. After downloading, I enter them into a sql table for faster querying; then with a few lines of code I get the information I need... hooray!. The trick is to convert the ip address you have to a proper address. Once you have that value you can compare it to your table to return the appropreate country, like so:
That's basically the gist of the script, maybe some error trapping would be nice. IIf you don't have access to a sql database you can alway manually look it up on the csv files or something, which would be slower. |



