473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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

Actually, I'm not sure if it's $_SERVER["REMOTE_ADDR"] -- 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_FORWARDED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
elseif (isset($_SERVER["HTTP_CLIENT_IP"]))
{
$visip = $_SERVER["HTTP_CLIENT_IP"];
}
else
{
$visip = $_SERVER["REMOTE_ADDR"];
}
}
else
{
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$visip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_CLIENT_IP'))
{
$visip = getenv('HTTP_CLIENT_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 12156
*** deko escribió/wrote (Sat, 30 Oct 2004 17:34:24 GMT):
Why is $_SERVER["REMOTE_ADDR"] returning multiple IP Addresses?

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


$_SERVER["HTTP_X_FORWARDED_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=$_SERVER['HTTP_X_FORWARDED_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_FORWARDED_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=explode(",", $visip);
return trim($ip_array[0]);
}
if (isset($_SERVER))
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARDED_FOR"];
$visip = realIp();
}
elseif (isset($_SERVER["HTTP_CLIENT_IP"]))
{
$visip = $_SERVER["HTTP_CLIENT_IP"];
}
else
{
$visip = $_SERVER["REMOTE_ADDR"];
}
}
else
{
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$visip = getenv('HTTP_X_FORWARDED_FOR');
$visip = realIp();
}
elseif (getenv('HTTP_CLIENT_IP'))
{
$visip = getenv('HTTP_CLIENT_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=explode(",", $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=explode(",", $visip);
return trim($ip_array[0]);
}
if (isset($_SERVER))
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARDED_FOR"];
$visip = realIp();
}

Don't rely on globals.

function realIp($unrealIp)
{
$ip_array = explode(",", $unrealIp);
return trim($ip_array[0]);
}
....
{
$visip = realIp($_SERVER['HTTP_X_FORWARDED_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=explode(",", $visip);
return trim($ip_array[0]);
}
if (isset($_SERVER))
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
$visip = $_SERVER["HTTP_X_FORWARDED_FOR"];
$visip = realIp();
}

Don't rely on globals.

function realIp($unrealIp)
{
$ip_array = explode(",", $unrealIp);
return trim($ip_array[0]);
}
...
{
$visip = realIp($_SERVER['HTTP_X_FORWARDED_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@databasix 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*******************@newssvr21.news.prodigy .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
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...
7
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: ...
5
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...
10
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?...
5
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 : ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.