Jump to content

How to get the address of remote host behind proxy server

- - - - -

  • Please log in to reply
4 replies to this topic

#1
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Hi,

I would like to retrieve the IP address of the remote hosts connected to an intranet application. When I use $_SERVER['REMOTE_ADDR'] variable, this contains the proxy server IP address. What is the correct technique to retrieve ip address of a host PC behind a proxy server in PHP? :confused:

Thanks

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You can't, without getting a result that is meaningless to you. Your only way to send messages back is via the proxy server IP address. You could use javascript to request the IP address from the client, but then it will be sending you a LAN address that you can't communicate with either.

The real question is: what are you trying to accomplish, and why is the proxy server IP address a problem?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Hi, the main reason is not for communication purposes but for audit but it is that the user logging shows the proxy server IP whenever it is logging access information, I would prefer it stored the IP address of the host (for audit purposes).

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
A non-standard standard of external proxies (i.e, squid which has implemented such) are to send X_FORWARDED_FOR (XFF) headers so that the host can differentiate between the external IP addresses of the proxy stream, although this is client set and should only be trusted if you know the client (i.e. in your department.)

Try the following: $_SERVER['HTTP_X_FORWARDED_FOR']

I would note if is compliant to this, it should give you a comma delimited list of IP addresses (i.e. client, proxy1, proxy2, load balancer 3...)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Thanks. I will try that out at the office and give you the feedback. We are using Apache 2.2.17.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users