Posted by Prakash Timilsina Sunday, February 14, 2010

Share
You must be using $_SERVER['REMOTE_ADDR'] in PHP to find the visitor's IP address. and you may also know that this will not return the true IP all the time, Because if your client is using the Proxy server then this will return back your client's proxy IP, so this is not correct all the time. to get the real IP of your visitor follow the steps.

First of all you need to make the function :


/*
* ComsGuru.blogspot.com
* Prakash Timilsina
*/
function TraceRealiP()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

Thanks, and i hope this works :)

1 Responses to Get Real IP Address in PHP

    v
  1. Anonymous Says:
  2. goood

      Posted on March 9, 2010 at 2:50 AM
:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Post a Comment

Goto Top