0

I have a simple web page in which the user will enter some information before submitting the form. I would like to retrieve his IPaddress after the post is done.

Mackintoast
  • 1,357
  • 5
  • 16
  • 25

2 Answers2

1

Here is function from another relevant post that should help:

function getUserIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
    {
        return $_SERVER['HTTP_CLIENT_IP'];
    }
    else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //if from a proxy
    {
        return $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
        return $_SERVER['REMOTE_ADDR'];
    }
}

This will cover the occasional proxy user and shared networks.

Community
  • 1
  • 1
Jeremy Harris
  • 23,837
  • 13
  • 78
  • 128
0

The code below should work:

<?php 
   echo $_SERVER['REMOTE_ADDR']; 
?>

Frankline
  • 39,030
  • 8
  • 41
  • 74