I use this (full code)
<html>
<head>
<title>Stop there!</title>
<META HTTP-EQUIV=REFRESH CONTENT="5;URL=http://www.skysim.net/airserbia/"> //redirects the user, change 5 to reflect the number of seconds that take for the user to be redirected
</head>
<body>
Dear visitor,<br>
You are not allowed to view this directory for security reasons.<br>
You will be redirected to the homepage in 5 seconds.<br>
<?php
$logfile= 'ip.html'; //the file where the logs will be saved..CHeck the privileges for the file
$IP = $_SERVER['REMOTE_ADDR']; //[b]gets the IP, dont touch anything below[/b]
$logdetails= date("F j, Y, g:i a O T") . ': ' .
'<a href=http://www.geobytes.com/IpLocator.htm?GetLocation&ipaddress='.$_SERVER['REMOTE_ADDR'].'>'
.$_SERVER['REMOTE_ADDR'].'</a>';
$fp = fopen($logfile, "a");
fwrite($fp, $logdetails);
fwrite($fp, "<br>");
fclose($fp);
echo("Your IP has been logged. It is $IP"); //[b]we call the IP to show up[/b]
?>
</body>
</html>