Jump to content

Getting a client's IP after a server URL maps to filesystem


Slickire

Recommended Posts

Hi, I am creating a simple traffic log for my homepage which is located on a university server. The web server automatically maps URLs of the form http://www.uniserver.ac.uk/~username/ to the filesystem path /homes/username/public_html/index.html. The problem is that instead of logging the clients IP address, my script will log the servers IP. How do i get the clients IP only?? I have tried searching for a solution, but to be honest i don't know how to properly describe it.

 

Here is part of the script that creates the log. It is PHP, but the file is called stats.cgi and is run everytime the homepage is requested:

 

 

    $userAgent = ( isset($_SERVER['HTTP_USER_AGENT']) && ($_SERVER['HTTP_USER_AGENT'] != ""))

                                                ? $_SERVER['HTTP_USER_AGENT'] : "Unknown";

     

    $userIp    = ( isset($_SERVER['REMOTE_ADDR']) && ($_SERVER['REMOTE_ADDR'] != ""))   

                                                ? $_SERVER['REMOTE_ADDR']    : "Unknown";   

 

    $refferer  = ( isset($_SERVER['HTTP_REFERER']) && ($_SERVER['HTTP_REFERER'] != ""))

                                                ? $_SERVER['HTTP_REFERER']    : "Unknown";

               

    $uri      = ( isset($_SERVER['REQUEST_URI']) && ($_SERVER['REQUEST_URI'] != ""))

                                                ? $_SERVER['REQUEST_URI']    : "Unknown";

 

    //$hostName  = gethostbyaddr($userIp);

    $actualTime = date(DATE_FORMAT);

 

    $logEntry = "<tr id=\"row\">

                              <td>$actualTime</td>

                              <td>$userIp</td>

                              <td>$hostName</td>

                              <td>$userAgent</td>

                              <td>$uri</td>

                              <td>$refferer</td>

                        </tr>";

 

Oh, the uni server is running php v4.3.0 if that helps, and Apache server version 1.3.27 on Linux. I only have access to my personal directory.

 

Cheers,

    Slicikire

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.