IP Addresses on the Front-End

Something that sort of bugs me in front-end development is the lack of support JavaScript has to detect a user’s IP. Detecting an IP address is inherently a server-side requirement…

I encountered some complications recently with logging errors from the end-user. We wanted to log the user’s IP from the support form already set up, but the proxy enabled by Cloudflare, unfortunately, masks the true IP, and as a result, it is difficult to try and detect what the original IP is.

This excellent answer on Stack Overflow details the numerous number of API options available, but there are certain caveats surrounding them; such as limitations on the number of requests for each IP, and tiered plans for each.

Nonetheless, we identified a very useful service to suite our needs; “ipify”:

https://www.ipify.org/

ipify is an excellent option for detecting IP addresses, as it does not rate limit, and provides seamless documentation for setup.

Here is a quick example of me setting up ipify within a single WordPress block:

Unbelievably simple, and very accessible.

I very much look forward to using this service on a wider scale.

Leave a comment

Your email address will not be published. Required fields are marked *