473,698 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is $_SERVER["REMOTE_ADD R"] returning multiple IP Addresses?

Why is $_SERVER["REMOTE_ADD R"] returning multiple IP Addresses?

Actually, I'm not sure if it's $_SERVER["REMOTE_ADD R"] -- or which if/else
statement -- that's the problem, but what I'm getting as a value for $visip
looks like this:

172.16.42.181, 62.138.35.94

Why am I getting more than one IP Address? Which IP is the originating IP
Address? Is there a way to get only the originating IP?

Here's the code:
if (isset($_SERVER ))
{
if (isset($_SERVER["HTTP_X_FORWARD ED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARD ED_FOR"];
}
elseif (isset($_SERVER["HTTP_CLIENT_IP "]))
{
$visip = $_SERVER["HTTP_CLIENT_IP "];
}
else
{
$visip = $_SERVER["REMOTE_ADD R"];
}
}
else
{
if (getenv('HTTP_X _FORWARDED_FOR' ))
{
$visip = getenv('HTTP_X_ FORWARDED_FOR') ;
}
elseif (getenv('HTTP_C LIENT_IP'))
{
$visip = getenv('HTTP_CL IENT_IP');
}
else
{
$visip = getenv('REMOTE_ ADDR');
}
}

You can view the page that displays the results here:

http://www.clearpointsystems.com/stats.php

(scroll to entry for Oct 29 2004 10:17 am and Oct 30 2004 05:26 am)

Thanks in advance.
Jul 17 '05 #1
7 12275
*** deko escribió/wrote (Sat, 30 Oct 2004 17:34:24 GMT):
Why is $_SERVER["REMOTE_ADD R"] returning multiple IP Addresses?

Actually, I'm not sure if it's $_SERVER["REMOTE_ADD R"] -- or which if/else
statement --


$_SERVER["HTTP_X_FORWARD ED_FOR"] is a comma-separated list of IP addresses,
though it's normally a one element list. This variable is the result of
intermediate proxies.

This function gets the first element:

function real_ip(){
if($tmp=$_SERVE R['HTTP_X_FORWARD ED_FOR']){
$tmpip=explode( ",", $tmp);
return trim($tmpip[0]);
}else return $_SERVER['REMOTE_ADDR'];
}
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #2
> $_SERVER["HTTP_X_FORWARD ED_FOR"] is a comma-separated list of IP
addresses,
though it's normally a one element list. This variable is the result of
intermediate proxies.


Ah, I see. Thanks for the help!
Jul 17 '05 #3
Follow up question:

How do I call the RealIp function? What I have below is not working.

function realIp()
{
$ip_array=explo de(",", $visip);
return trim($ip_array[0]);
}
if (isset($_SERVER ))
{
if (isset($_SERVER["HTTP_X_FORWARD ED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARD ED_FOR"];
$visip = realIp();
}
elseif (isset($_SERVER["HTTP_CLIENT_IP "]))
{
$visip = $_SERVER["HTTP_CLIENT_IP "];
}
else
{
$visip = $_SERVER["REMOTE_ADD R"];
}
}
else
{
if (getenv('HTTP_X _FORWARDED_FOR' ))
{
$visip = getenv('HTTP_X_ FORWARDED_FOR') ;
$visip = realIp();
}
elseif (getenv('HTTP_C LIENT_IP'))
{
$visip = getenv('HTTP_CL IENT_IP');
}
else
{
$visip = getenv('REMOTE_ ADDR');
}
}
Jul 17 '05 #4
*** deko escribió/wrote (Sat, 30 Oct 2004 19:33:01 GMT):
function realIp()
{
$ip_array=explo de(",", $visip);
return trim($ip_array[0]);
}


I don't know what your code tries to do but if you want to use variables
that are external to the function you must either:

1) Pass them as parameters:

function realIp($visip)
{
...
}
2) Declare them as global:

funtion realIp()
{
global $visip;
...
}
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #5
"deko" <ww************ *************** ****@nospam.com > wrote:
Follow up question:

How do I call the RealIp function? What I have below is not working.

function realIp()
{
$ip_array=explo de(",", $visip);
return trim($ip_array[0]);
}
if (isset($_SERVER ))
{
if (isset($_SERVER["HTTP_X_FORWARD ED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARD ED_FOR"];
$visip = realIp();
}

Don't rely on globals.

function realIp($unrealI p)
{
$ip_array = explode(",", $unrealIp);
return trim($ip_array[0]);
}
....
{
$visip = realIp($_SERVER['HTTP_X_FORWARD ED_FOR"]);
}

What makes you think the first IP in the list is any more "real" than any
of the others? Do you hope to use this for some kind of validation? If
so, the numbers are quite unreliable.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #6
On Sun, 31 Oct 2004 14:39:17 -0800, Tim Roberts <ti**@probo.com >
wrote:
"deko" <ww************ *************** ****@nospam.com > wrote:
Follow up question:

How do I call the RealIp function? What I have below is not working.

function realIp()
{
$ip_array=explo de(",", $visip);
return trim($ip_array[0]);
}
if (isset($_SERVER ))
{
if (isset($_SERVER["HTTP_X_FORWARD ED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARD ED_FOR"];
$visip = realIp();
}

Don't rely on globals.

function realIp($unrealI p)
{
$ip_array = explode(",", $unrealIp);
return trim($ip_array[0]);
}
...
{
$visip = realIp($_SERVER['HTTP_X_FORWARD ED_FOR"]);
}

What makes you think the first IP in the list is any more "real" than any
of the others? Do you hope to use this for some kind of validation? If
so, the numbers are quite unreliable.

Exactly. If there's more than one IP, you'd have to validate for each
one or all of them at once.

--
gburnore@databa six dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
=============== =============== =============== =============== ===============
Want one? GET one! http://signup.databasix.com
=============== =============== =============== =============== ===============
Jul 17 '05 #7
"deko" <ww************ *************** ****@nospam.com > wrote in message news:<Ag******* ************@ne wssvr21.news.pr odigy.com>...
<snip>
Is there a way to get only the originating IP?


<snip>

Try i2c_realip() available at
<http://in2.php.net/source.php?url=/include/ip-to-country.inc>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4192
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens in IE as well as FireFox. This code has been tested on a Win2003 server, IIS6, PHP 5.0.3, mySQL 4.1.8 and it works fine. The problem server is a Win2k server, IIS5, PHP 5.0.4, mySQL 4.1.11.
7
2156
by: rynato | last post by:
Simple question, probably a simple answer: I have a php-based email form. There are three hidden variables passed from the initial page to the php script which handles sending the message: <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?
5
3544
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function createNewFile($name,$mail,$subject,$comments,$count,$date,$other="",$up="0") { global $settings; $header=implode('',file('header.txt')); $footer=implode('',file('footer.txt')); $content=' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
10
2300
by: Breana | last post by:
Ok i found this a while back and i am trying to mod it so it works but it keeps not updating the users online and kills my other code? Well i got it working but it dont update when i login? It says 14 guest now, and i am logged in so it sould ream me as member..... And how do i make a cron job, the tutorial says it lowrs site badwith and it runs better updating records?
5
7364
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : $http_ref= $HTTP_REFERER; $prog = $_COOKIE;
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.