Solved

Show Proxy IP or Real IP

Posted on 2004-10-11
13
1,250 Views
Last Modified: 2007-12-19
hello there,
i want to show in php that if im using a proxy
---------
Proxy IP: 81.26.35.62
Host: 81-26-35-62.speedyterra.com
Your Real IP Is: 24.157.108.253
Your Real Host Is: adsl-24-27-108.isp.com
---------

but if i am not using a proxy just
---------
Your Real IP Is: 24.157.108.253
Your Real Host Is: adsl-24-27-108-.mia.isp.com
---------

this is what i have

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$raddr = trim(getEnv("REMOTE_ADDR")); if (getenv("HTTP_X_FORWARDED_FOR")!="")
$raddr = getenv("HTTP_X_FORWARDED_FOR"); if (getenv("HTTP_CLIENT_IP")!="")
$raddr = getenv("HTTP_CLIENT_IP");
$realhost = gethostbyaddr($raddr);

echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
echo "Your Real IP Is: $raddr<BR>";
echo "Your Real Host Is: $realhost<BR>";
?>
0
Comment
Question by:Xtry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12281328
add a condition around the first two echos:

if (getenv("HTTP_X_FORWARDED_FOR") || (getenv("HTTP_CLIENT_IP") ) {
echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
}

echo "Your Real IP Is: $raddr<BR>";
echo "Your Real Host Is: $realhost<BR>";
0
 
LVL 2

Expert Comment

by:hewtluca
ID: 12281867
Try this:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
 if ($_GET['HTTP_X_FORWARDED_FOR'] || $_GET['HTTP_CLIENT_IP']) {
$raddr = $_GET['HTTP_X_FORWARDED_FOR'] ;
$raddr = $_GET['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $ip <BR>";
             echo "Host: $realhost";
} else{

$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>

Regards
0
 

Author Comment

by:Xtry
ID: 12286920
Hello there
Thanks for all replies,, hewtluca your code is working but if i am using a proxy or my real ip
It shows me your real ip is 81.35.65.32 both ways
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 2

Expert Comment

by:hewtluca
ID: 12287131
Opps try this:

<?php

 if ($_GET['HTTP_X_FORWARDED_FOR']) {
$raddr= $_GET['HTTP_X_FORWARDED_FOR']  || ;
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
}elseif ($_GET['HTTP_CLIENT_IP']){
$raddr  = $_GET['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
} else{
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>
Regards
0
 
LVL 2

Expert Comment

by:hewtluca
ID: 12287142
Dag I must be half asleep, this should work, scratch my last post.

<?php

 if ($_GET['HTTP_X_FORWARDED_FOR']) {
$raddr= $_GET['HTTP_X_FORWARDED_FOR'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
}elseif ($_GET['HTTP_CLIENT_IP']){
$raddr  = $_GET['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
} else{
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>
Regards
0
 

Author Comment

by:Xtry
ID: 12287192
hehehe np man.
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 200 total points
ID: 12287228
hewtluca have you verified that the HTTP_X_FORWARDED_FOR is defined in the superglobal $_GET ? It is typical only located in $_ENV or via getenv()

This should give you the output you wanted:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$raddr = trim(getEnv("REMOTE_ADDR")); if (getenv("HTTP_X_FORWARDED_FOR")!="")
$raddr = getenv("HTTP_X_FORWARDED_FOR"); if (getenv("HTTP_CLIENT_IP")!="")
$raddr = getenv("HTTP_CLIENT_IP");
$realhost = gethostbyaddr($raddr);

if (getenv("HTTP_X_FORWARDED_FOR") || (getenv("HTTP_CLIENT_IP") ) {
echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
}

echo "Your Real IP Is: $raddr<BR>";
echo "Your Real Host Is: $realhost<BR>";
0
 

Author Comment

by:Xtry
ID: 12287243
Your Real IP Is: $raddr
Your Real Host Is: $realhost
Proxy IP: $ip
Host: $fullhost
0
 

Author Comment

by:Xtry
ID: 12287271
thanks hernst42,
using proxy only thing i see is

Your Real IP Is:
Your Real Host Is:
0
 
LVL 2

Accepted Solution

by:
hewtluca earned 300 total points
ID: 12287336
I told you I was half a sleep :)  Try this.  I am not actually verifiying these, because I should know them.

<?php

 if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
$raddr= $_SERVER['HTTP_X_FORWARDED_FOR'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$raddr  = $_SERVER['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
} else{
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>
Regards
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12287364
If you only get those two line then the proxy your are using does not forward that information. You might add the following to get more infromation:

if (getenv("HTTP_X_FORWARDED_FOR") || (getenv("HTTP_CLIENT_IP") ) {
echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
} else {
    var_dump($_ENV);
}

Perhaps in the dump you see your real IP adress and in which variable it is stored.
0
 

Author Comment

by:Xtry
ID: 12287876
thank you guys
0
 

Author Comment

by:Xtry
ID: 12287880
i got all the information i needed!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question