I often see people asking for an easy free solution so here goes
p.s. because its free its not perfect but it also is alot less tasking on your server than most free methods
exampe usage of below code
http://ytmnd.webspacemania.com/freegeo/
Code:
<html>
<head>
</head>
<body>
Hi, I'm Brooke i live in
<?php
// ip to html by stb
$addr = getenv("REMOTE_ADDR");
$url = "http://api.hostip.info/get_html.php?ip=$addr&position=true";
$html = file_get_contents($url);
$trip = explode('Latitude:',$html);
$ctcn = $trip[0];
$trip = explode('City: ',$ctcn);
$ctcn = trim($trip[1]);
echo $ctcn;
?>
and i'm super horny
</body>
</html>