get user's country code
I want to use on my site a script that shows the user's country code. I know about maxmind.com's GeoIP PHP API, but I can't install the mod_geoip (not my own server)开发者_运维技巧 :(
Apache mod_geoip
is an Apache module, not a PHP-specific library. There are PECL bindings for GeoIP that can be used instead of mod_geoip
, but these probably also require access to your server configuration. However, there exists also a pure PHP module that can easily be inserted into an existing app (does not require either PECL bindings or mod_geoip
) found here.
Use the browser language setting, instead. Nothing more annoying than being on vacation/business in a foreign country and getting the wrong language because it's assuming anyone from that IP speaks that language.
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
this is a bad solution - but you can create a service on another server which you can control and have it publish a method that gets the user ip , do the work, and return the answer to the current server. also - most php shared server has a way to change php.ini setting for a single website, check with the hosting company.
精彩评论