How to detect ISP with PHP?

Getting ISP (internet service provider) of a client is possible with using gethostbyaddr function which will attempt to retrieve clien’t host by its IP address:

Simple example:


$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;

But important for you to know is that relying on this is not always possible since the client may be logged in through VPN.

GitHub OctocatFound a typo? Something wrong with this content? Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all the contributors.