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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.