WordPress Code Snippets

A fresh mix of code snippets and tutorials

PHP Get Actual IP Address


Here are a couple of quick snippets to get the visitor’s actual IP address via PHP.

Method 1

This is the method that I use in my projects to get the actual IP address:

This is a plug-n-play snippet with no modification necessary. Just include in your script and call/use $address as needed. Covers just about every possible IP-address scenario.

Update! Here is a minimized version of the previous get-IP function:

That’s a bit nicer for copy/paste and quick-use scenarios.

Method 2

Here is another snippet found lurking in the archives. It’s a bit more comprehensive in that it returns not just a single IP address, but an entire array of all possible IP addresses. Great for serious IP analysis..

Again, this snippet is plug-n-play with no modification required. Just plop it in and call the $ip array as needed. The future is yours!

Show Support

Like our new Facebook Page to show support!