how to detect ip address based location using PHP

I am interested in finding out if there is a reliable and economical way for extracting user's location based on his ip address, using php

I tried to get the job done using ip2location.com, but I am not happy how it deals with result inconsistently.

Unfortunatly, there's no really simple way to do this. While IP space generally maps to geographical location, this mapping is completely arbitrary, and subject to change if an IP range is sold.
One option is to use the whois service to find the owner of an IP block, then report the address they have defined there - it's not exact as this address field is free-form and/or could easily be a bald-faced lie, but it might get you part-way there...

These turns up with PEAR and PECL:

PEAR :: Search: geo
PECL :: Package Search

As mentioned, the results are not necessarily accurate (some are known false results). Say, my company owns an AS and have a range of IPs allocated, that are assigned to locations at different parts of the world. Of course, if you look at netblock owner the location will be that of our company headquarters, but that does not represent the location of our servers which really got assigned those IPs. To date, I have yet to see a geolocation service or package that guesses the locations of those offshore servers right.

So, don't treat these kind of geolocation data too seriously. It will be good for, say, selecting a default language for a multi-lingual site based on an estimated location (that the user can still switch if the guess is wrong). Don't expect you will find a source, no matter how much you are willing to pay, that gives you "accurate" results, let alone zero false results.