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,397
  • 5
  • 17
  • 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
  • 24,318
  • 13
  • 79
  • 133
0

The code below should work:

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

Frankline
  • 40,277
  • 8
  • 44
  • 75