473,839 Members | 1,438 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 12303
*** 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 informticas recibidas por correo irn 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 informticas recibidas por correo irn 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
4201
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
2161
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
3566
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
2311
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
7373
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
9856
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10914
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
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7834
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
7022
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();...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4495
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
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.