So that you can register it in a database with visitor details and check against white and blacklists for known spammers

Took me a while to get this one right, so here it is; really very simple

<?php

function GetIP()
{
global $ip;
$ip=$_SERVER['REMOTE_ADDR'];
}
?>