Retrieving IP address and hostname from user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bill1one
Forum Newbie
Posts: 8
Joined: Thu May 24, 2007 2:12 pm

Retrieving IP address and hostname from user

Post by bill1one »

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:

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';
 
?>
 
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.
User avatar
lukewilkins
Forum Commoner
Posts: 55
Joined: Tue Aug 12, 2008 2:42 pm

Re: Retrieving IP address and hostname from user

Post by lukewilkins »

To my knowledge, I do not think there is a way around this. This happens within basically any form of network. The internet is going to see the same outward facing IP for any of those computers.

Maybe I'm wrong, in which case I'd like to see this also.
Post Reply