?
Solved

Show Proxy IP or Real IP

Posted on 2004-10-11
13
Medium Priority
?
1,259 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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
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 800 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 1200 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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