Retrieving IP address and hostname from user
Posted: Mon Aug 11, 2008 12:21 pm
I am trying to log ip addresses and hostname of users of the Internet on our LAN. Each user when they open their browser goes through ipcop to a PHP with the following code:
This code works fine, in that it retrieves the ip address and hostname of the user, but since it is passing through ipcop, it picks up the ip address and hostname of the ipcop machine. So essentially I get the same ip and host for every user. Can anyone help me figure a way to pass original ip and host through ipcop.
Thanks. Bill.
Code: Select all
<?php
function ip()
{
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$vip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else $vip=$_SERVER['REMOTE_ADDR'];
return trim($vip);
}
$ip = ip();
$hostname = gethostbyaddr($ip);
include 'config.php';
include 'opendb.php';
$sql = "INSERT INTO tbl_log (ip, hostname)" .
"VALUES ('$ip', '$hostname')";
mysql_query($sql);
header( 'Location: LINK TO INTERNAL WEB SITE' ) ;
include 'closedb.php';
?>
Thanks. Bill.