How to get real IP Address wen PC is running behind PROXY

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

How to get real IP Address wen PC is running behind PROXY

Post by poddar_ravi »

I was tryin to get the real IP, and used following code

Code: Select all

// This function returns the Client side IP Address
function getIP(){
         $ip;
         if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
            else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
                 else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
                      else $ip = "UNKNOWN";
         return $ip;
         }
But the thing is My machine is running behind proxy, and it is not giving me client IP, it is always givin me REMOTE_ADD ie 127.0.0.1. Is there any way to get the real IP of my machine, I think There is something wrong in APACHE server. how can i update the env var in apache.
Last edited by poddar_ravi on Thu Aug 31, 2006 6:12 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You might change the proxy's configuration and have it forward the ip.
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

I have changed the proxy setting, but still it is not working.
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

In my phpInfo.php page

Apache Environment
REMOTE_ADDR
is 127.0.0.1

but
HTTP_X_FORWARDED_FOR
is not shown there.[/quote]
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You could actually search this forum ... And find out that you won't get any further than 'a best effort' result...
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

can anybody help me to set the environmental variable of APACHE

I have used

Code: Select all

apache_setenv("VAR NAME","VALUE");
But the thing is if i will hardcode this thing, this will not work in the situation where i have to track the user's IP and according to Tracked IP i have to generate reports.

Thanx in Advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What proxy (for incoming connections) do you use?
What settings did you change to make it append the sender's ip?
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

Hi,
I have changed the manual proxy setting as follows

HTTP Proxy:172.16.16.3
and checked on use this proxy server for all protocols

Now everytime i am gettin the REMOTE_ADDR that is 127.0.0.1

My problem is i am not able to get following variables

1. HTTP_CLIENT_IP
2. HTTP_X_FORWARDED_FOR
Plz help me out to get the value of HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR variables.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

volka wrote:What proxy (for incoming connections) do you use?
Or didn't you change any settings on your server but e.g. for the client-side internet explorer?
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

Yes Mr. Volka

I have not changed anything on SERVER SIDE, i have changed it on the client side only (I am using Mozilla).
Actually i am working in a Software Company, so my PC is behind proxy. Whenever i try to capture my Public IP address, I get only REMOTE_ADDR. I want to capture my Public IP. I am using PHP and apache.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If the proxy does not add the ip the webserver is unable to determine the client's ip.
The connection to the webserver is established by the proxy and therefore remote_addr shows the ip of the proxy.
Last edited by volka on Fri Sep 01, 2006 6:44 am, edited 1 time in total.
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

So i cannot get Public IP of any organisation , if the server is configured not to pass related information ie IP.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You can get the ip of their proxy/nat server.
But no, I haven't heard of a browser that sends its own ip as request header. Maybe you can find an addon for mozilla doing that. And maybe then the proxy filters it out again - it really depends on the proxy's configuration ;)
poddar_ravi
Forum Newbie
Posts: 8
Joined: Thu Aug 31, 2006 4:02 am

Post by poddar_ravi »

Thanx volka.. many many thanx :)
Post Reply