By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

problem with REMOTE_ADDR

P: n/a
I want to put a script on my site that shows how many users are online
on my site. I found one, and that is shown below. It also shows a
log with the IP-addresses of those visitors. Buuut... the counter
always stays on 1...
When I look at the log, every visitor seems to have the same
IP-address. When I look up that address, I see it is from the host of
my webspace.

Can someone offer me a solution?
Thanx,

Bart
<?php
################################################## ######################
# Copyright 2001 Wanja Hemmerich
#
# First version published April 2001 - This version November 2001
#
################################################## ######################
# COPYRIGHT NOTICE
#
# Copyright 2001 Wanja Hemmerich. All rights reserved.
#
#
#
# This program may be used and modified, as long as this copyright
#
# notice stays intact.
#
#
#
# Wanja Hemmerich is not responsible for damage, which is possibly
#
# caused by his program.
#
#
#
# This program code may not be sold, nor auctioneered, nor be used in
#
# any other commercial way in order to make money.
#
#
#
# This Programm may not be distributed to download neither by
#
# Internet, nor by another medium.
#
################################################## ######################
# By using this programm, you agree with these conditions.
#
#
#
################################################## ######################
# The text above must be kept intact under all circumstances.
#
################################################## ######################
include ("./config.php3");

if (!$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = getenv("REMOTE_ADDR");
$string = "$ip|$time\n";
$a = fopen("$filename", "a+");
fputs($a, $string);
fclose($a);

$timeout = time()-(60*$timer);

$all = "";
$i = 0;
$datei = file($filename);
for ($num = 0; $num < count($datei); $num++) {
$pieces = explode("|",$datei[$num]);

if ($pieces[1] > $timeout) {
$all .= $pieces[0];
$all .= ",";
}
$i++;
}

$all = substr($all,0,strlen($all)-1);
$arraypieces = explode(",",$all);
$useronline = count(array_flip(array_flip($arraypieces)));

// display how many people where activ within $timeout
echo $useronline;

// Delete
$dell = "";
for ($numm = 0; $numm < count($datei); $numm++) {
$tiles = explode("|",$datei[$numm]);
if ($tiles[1] > $timeout) {
$dell .= "$tiles[0]|$tiles[1]";
}
}

if (!$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = getenv("REMOTE_ADDR");
$string = "$dell";
$a = fopen("$filename", "w+");
fputs($a, $string);
fclose($a);
?>
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try

$_SERVER["REMOTE_ADDR"]

instead.
--
Bob
London, UK
echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk"
Jul 17 '05 #2

P: n/a
> Try

$_SERVER["REMOTE_ADDR"]

instead.


the problem remains :s ...
Some other scripts also take the IP from the users, and that works...
Jul 17 '05 #3

P: n/a
bawar wrote:
Try

$_SERVER["REMOTE_ADDR"]

instead.

the problem remains :s ...
Some other scripts also take the IP from the users, and that works...


$_SERVER["REMOTE_ADDR"] gives you your own IP address? That is weird.
Sounds like some funky-ass network configuration your web host is using.
(Like a bad proxy server which only reports its IP.) If so, I don't
think you'll be able to fix that. Web hosts are very stubborn about
fixing their network setups. I'm trying to persuade mine to get the
latest version of PHP 'cause a script I've written depends on a new
function.

Ah, to be able to run a server from home on a fat connection...
--
Bob
London, UK
echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk"
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.