Get country location of an IP with native PHP

前端 未结 8 1084
野性不改
野性不改 2020-12-23 16:46

Read on before you say this is a duplicate, it\'s not. (as far as I could see)

I want to get the county code in php from the client.

Yes I know you can do th

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 17:11

    Whois is just a client for the whois service, so technically you are still relying on an outside site. For the queries that fail, you could try falling back to another site for the query, such as hostip.info, who happen to have a decent API and seem friendly:

    http://api.hostip.info/country.php?ip=4.2.2.2
    

    returns

    US
    

    Good luck,

    --jed

    EDIT: @Mint Here is the link to the API on hostip.info: http://www.hostip.info/use.html

提交回复
热议问题