Monday, March 31, 2008

PHP: Getting your user's IP Address

It's easy, just use $SERVER['REMOTE_ADDR']. Echoing the user's IP address would look something like this:

echo "IP Address: " . $SERVER['REMOTE_ADDR'];
But that works only in PHP versions greater than 4.1.0. If you're still using earlier versions, use HTTP_SERVER_VARS, and for heavens' sake, upgrade.

Source: PHP: Predefined Variables - Manual (This page should be on the thumbs of all PHP developers)