top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I find a visitors IP address using PHP?

+1 vote
111 views
How can I find a visitors IP address using PHP?
posted Jun 30, 2014 by Amritpal Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
<?PHP
function getUserIP()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    return $ip;
}

$user_ip = getUserIP();
echo $user_ip; // Output IP address [Ex: 177.87.193.134]
?>

You can get more help using dissertation writing using uk writers.

answer Jul 1, 2014 by Daniel Taylor
0 votes

A common requirement is to be able to log or store the IP address of a visitor to your website.
In order to do this, you can easily access the IP address through an environment variable.
The one that you want for the IP Address is called $REMOTE_ADDR, so you can access it like this:
<?php $ip = $REMOTE_ADDR; echo "Your IP address is $ip"; ?>

answer Jul 1, 2014 by Rahul Mahajan
Similar Questions
+1 vote

I want to count the number of active user in website and also I have to display their IP Address by using python Django framework.

+3 votes

Any opensource code would be a great help :)

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...