Generally, according to IP if you want to show country then you may get it from net searching on google.
You need to look for an IP to (Country/City/etc.) script. There are a number of free and paid scripts, API's, and database dumps out there depending on how accurate you need the info to be.
I don't know why people always go to the database solution when it comes to it. I recommend MaxMind GeoIP solution, a binary file + an api class that they provide freely. I think the binary file solution is better than DB because it's easier to update (they release an update every month) and takes much less space. You can find it at http://www.maxmind.com/app/geolitecountry
<? if (getenv(HTTP_X_FORWARDED_FOR)) { $ip_address = getenv(HTTP_X_FORWARDED_FOR); } else { $ip_address = getenv(REMOTE_ADDR); } ?> You can get the Ip address from this code, after that got a IP number and then find a country.
I don't want to get picky, as sometimes people right code fast on comments, but I still would like to comment that although the above code works it will still produce Notice errors. It's important to use ' when using strings to avoid all errors. If you want better code you should always show E_NOTICE errors as well and make sure to avoid them. So the above code should look like: And a small clarification about it, what it does is to also give you the real IP in-case the user is using a proxy.