Solved

Show Proxy IP or Real IP

Posted on 2004-10-11
13
1,245 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
Industry Leaders: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

761 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