Get a visitors IP using PHP

Getting a users IP address can be useful for a number of reasons including preventing spam etc.

To access the ip address can be done via the $_SERVER array, using the REMOTE_ADDR field.

$ip = $_SERVER['REMOTE_ADDR'];