Gossamer Forum
Home : Products : Links 2.0 : Customization :

visitors online = ?

Quote Reply
visitors online = ?
Is there any hack to show how many visitors are on site at the moment when someone enter the site?

www.midi-studio.com
Quote Reply
Re: visitors online = ? In reply to
I do not know of any. But, it shouldn't be that hard to implement such a hack. What you could do is write a little script that records the visitors IP and access time. Then you'd run a while() loop on the file, looking for accesses from unique ID's within the last 'x' minutes, and incrementing a counter. Then you can just return that number via SSI or whatever method you want. For efficiency's sake, you would also want to purge old records during the while loop, then rewrite the file.

If you need further help with this, I'd be glad to right up some basic code.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? In reply to
this took a couple minutes to write...I tested it on my pc so it looks like it should work for you.

save the following to a file called 'users.cgi'. chmod the file to 755.
Code:
#!/usr/local/bin/perl
use strict;
my $log = '/home/camelsoup/www/cgi-bin/data';
my $ip = $ENV{REMOTE_ADDR};
my $now = time();
my %ip;
my $count = 1;
open (LOG, "$log/log.db") or die("Could not open log file for reading: $!");
open (TEMP, ">$log/temp.db") or die("Couldn't create temp log file: $!");
flock (TEMP, 2);
while (<LOG>) {
chomp;
my @data = split /\|/, $_;
(($now - $data[1] > 600) or ($ip eq $data[0]) or (exists $ip{$data[0]})) and next;
$ip{$data[0]} = 1;
$count++;
print TEMP join("|", @data), "\n";
}
print TEMP join("|", ($ip, $now)), "\n";
close (TEMP);
close (LOG);
rename ("$log/temp.db", "$log/log.db");
print "Content-type: text/html\n\n";
print $count;
Create a file named 'log.db' and chmod it to 666. Put the full path (not including the file name), in the $log variable.

Then you can use an exec-cgi SSI call or similar in your home page.

It will count the number of unique IP's that have visited the page within the last 10 minutes (note the "600" in the code above is 60 seconds * 10 minutes).

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? In reply to
Thank you Junko. I have done everything as you said and add folowing code into my html:
< !--#exec cgi="/cgi-bin/users.cgi"-- >
but it returns NO DETAIL, i just got blank page. Also i was connected to my site to make shure there is someone but same!
What could be wrong?

www.midi-studio.com
Quote Reply
Re: visitors online = ? In reply to
Ohh i got it. It working in .shtml pages, but all my templates are in .html, is there anything i can use in html insted of changing all templates?

www.midi-studio.com
Quote Reply
Re: visitors online = ? In reply to
Instead of using SSI, you can use JavaScript:
Code:
<script language="JavaScript" src="http://www.yoursite.com/cgi-bin/users.cgi">
</script>
Then in the script change:
Code:
print $count;
to:
Code:
print qq|document.write "$count"|;
IFRAME's and ILAYER's work as well, but you have to run a broswer test to know which to use.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? In reply to
Done but again no details returned in html. By the way what IFRAME's and ILAYER's mean?

www.midi-studio.com
Quote Reply
Re: visitors online = ? In reply to
IFRAME allows you to insert scripts and other files within web pages (works only for IE and Netscape 6.0 and above) and ILAYER does the same thing (works only for Netscape 2.02 - 4.76).

Also, you could try simply using:

Code:

<SCRIPT SRC="/something.cgi"></SCRIPT>


Want to see an example?

Go to http://vlib.anthrotech.com and look at the HTML source code...search for SCRIPT and you will see how the script works.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: visitors online = ? In reply to
I have to admit I know nothing about JavaScript Smile.

In the script, you should have:
Code:
print qq|document.write ($count);|;
That seemed to work fine in my test.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? In reply to
Thanks a lot. Last option work just as i wish!!

www.midi-studio.com
Quote Reply
Re: visitors online = ? In reply to
If you need further help with this, I'd be glad to right up some basic code.

Then...

"this took a couple minutes to write...I tested it on my pc so it looks like it should work for you."

Within an hour you go from answering a question to writing a mod...you guys are a trip! Wink

Thanks for an interesting little mod to play with...

Perl Hopefull
Quote Reply
Re: visitors online = ? In reply to
Hummmmm
i use the 2 versions and not work! :O(
http://www.lokirj.com.br/powerbusca/teste.shtml

A very long time i want this script in .cgi version :O)


Quote Reply
Re: visitors online = ? In reply to
please post the last 10 lines of the script.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? In reply to
lokirj - you do not need to use java script in shtml page as you put:
<script language="JavaScript" src="http://www.lokirj.com.br/powerbusca/cgi-bin/uonline.cgi"></script>

just try to put call to SSI like:
< !--#exec cgi="/cgi-bin/users.cgi"-- > or on some servers need to be like this:
< !--#exec cgi="cgi-bin/users.cgi"-- >

java script is used to show details in html pages i think!!



www.midi-studio.com
Quote Reply
Re: visitors online = ? In reply to
Ok.....
I use this command in .shtml file because my server accept:

Nothing happens! the page is blank, look:
http://www.lokirj.com.br/powerbusca/teste.shtml

my "log.db" is create into cgi-bin and chmod 666


My uonline.cgi

#!/usr/bin/perl

use strict;
my $log = '/home/lokirj/www/powerbusca/cgi-bin';
my $ip = $ENV{REMOTE_ADDR};
my $now = time();
my %ip;
my $count = 1;
open (LOG, "$log/log.db") or die("Could not open log file for reading: $!");
open (TEMP, ">$log/temp.db") or die("Couldn't create temp log file: $!");
flock (TEMP, 2);
while (<LOG>) {
chomp;
my @data = split /\|/, $_;
(($now - $data[1] > 600) or ($ip eq $data[0]) or (exists $ip{$data[0]})) and next;
$ip{$data[0]} = 1;
$count++;
print TEMP join("|", @data), "\n";
}
print TEMP join("|", ($ip, $now)), "\n";
close (TEMP);
close (LOG);
rename ("$log/temp.db", "$log/log.db");
print "Content-type: text/html\n\n";
print $count;

Thanks for help!
Giovanni


Quote Reply
Re: visitors online = ? In reply to
Is the directory you have the scripts in CHOMD to 777.
Good Luck,
Paul

Hot Web Hosting
Low cost web hosting:
http://www.thehotweb.net/webhosting
Quote Reply
Re: visitors online = ? In reply to
The directory set to 755 because the directory is "cgi-bin"

Quote Reply
Re: visitors online = ? In reply to
UUUUUUUUUUUU!
it's workkkkkkkk!
i put the "log.db" into a directory and chmod this to 777
Thanks everybody!

Quote Reply
Re: visitors online = ? In reply to
If you can upload a custom .htaccess you could add the following to it:
AddHandler server-parsed .html .htm .shtml
Options Includes ExecCGI


http://www.irishsearch.net/
Quote Reply
Re: visitors online = ? under win32 In reply to
I am using win98 and apache for win32
So I am interesting in should this script work on my system?
I have already made all changes which people described below and there is no any effect (just blank page).
PS I am using java include.

Quote Reply
Re: visitors online = ? under win32 In reply to
several users (besides myself) have already confirmed that this mod works. Both the SSI and JavaScript version work fine, you just need to re-read this thread on how to get it work, and what, if any, changes need to be done.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? under win32 flock error In reply to
Do you think it actually works under win32 (windows98)?
I have already read all of these threads and there are no any words about win32.
And so what I found myself:
1. I created users.cgi (version 1.0).
2. I created info directory in cgi-bin directory.
3. Created log.db file in info dir.
4. Of course it doesn`t work in both java and SSI methods (with changes in users.cgi described in forum).
5. I renamed users.cgi to users.pl and run it.
6. Then I recieved following error: flock() unimplemented on this platform at D:\site\cgi-bin\users.pl line 10.
7. Line 10 is: flock (TEMP, 2);
8. Your comments?

Quote Reply
Re: visitors online = ? under win32 flock error In reply to
Flock does not work on Windows 9X servers. You need to turn off flocking.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: visitors online = ? under win32 flock error In reply to
yes, I'm absolutely certain it runs on Win32. 99% of the time I write and test my programs on Windows98/ME. Yes, flock does not work, but it is there for the Unix folks. All you need to do is comment or remove the line. I assumed that anyone running Links on Windows knows that flock has to be turned off in the config file for it to run, and would have the sense to remove it if they saw it in another program!

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: visitors online = ? under win32 flock error In reply to
ok thank you. I turned off flock.
Everything is ok. Script works.

Quote Reply
Re: visitors online = ? In reply to
***Sorry for being fussy***

Code:
my @data = split /\|/, $_;
...can be just...

Code:
my @data = split /\|/;
Installations:http://www.wiredon.net/gt/

Quote Reply
Continue of topic visitors online. In reply to
So it was a good idea to make a counter like this. I am really enjoing using it. But I found a bug (maybe really it is not a bug).
Example: There are 2 persons currently are online. And both of them are using THE SAME PUBLIC PROXY SERVER (not anomim.). And that`s why counter shows ONLY 1 PERSON IS ONLINE.
_______________________
I know that public proxies do not change user ip, and anonimous proxies do.
So is there any way to fix this problem?
____________________________
PS I really like this counter %)

Quote Reply
Re: [DenisSlinkin] Continue of topic visitors online. In reply to
having problems, every time I access the page, and I know there are other visitors online it only shows 1. I have another php counter to show online users and it sometimes says I have 22 visitors online. I had another person I showed this code to say the same thing.
thanks,
Paul
Webmaster Discussions
Quote Reply
Is this the problem In reply to
Is this the problem:
Here you have the following to print out:
print $count;

isn't that just calling the my $count which is set at 1 like this:
my $count = 1;
Thanks,
Paul
Webmaster Discussions
Quote Reply
Re: [hacker] Is this the problem In reply to
DenisSlinkin,

an alternate method would be to set cookies and have randomly generated session ID's stored in the cookie.

Hacker,

aside from what DenisSlinkin mentioned, it also has to do with when a certain user is expired. You php script may have a longer period of time before a user is considered inactive and is removed.

I'll post an update for this sometime in the next couple weeks.

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] Is this the problem In reply to
Drew I really dont think that's it, my PHP script is set at 15 minutes and this is set at 10. Let me check very quickly if this is even logging the data into the DB.
Thanks,
Paul
Webmaster Discussions
Quote Reply
Re: [hacker] Is this the problem In reply to
Nope doesn't even log this. My permissions are set at 777 for the loo files. I did try 666 and that didn't work eighter. My directory the script is in is set 777. Maybe the problem is in where it renames the temp.db script. Do we really need this step or can we just skip to log.db.
Thanks,
Paul
Webmaster Discussions
Quote Reply
Re: [hacker] Is this the problem In reply to
Nope this isn't even logging the IPs to the database, it only has 1. Can someone please help, I want to incorporate this into a portal script I will write for my links site.
Thanks,
Paul
Webmaster Discussions
Quote Reply
Re: [hacker] Is this the problem In reply to
can you show me what code you are using in the script and how you are calling it from within your templates?

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] Is this the problem In reply to
use strict;
my $log = '/home/fanaticn/www/cgi-bin/counter';
my $ip = $ENV{REMOTE_ADDR};
my $now = time();
my %ip;
my $count = 2;
open (LOG, "$log/log.db") or die("Could not open log file for reading: $!");
open (TEMP, ">$log/temp.db") or die("Couldn't create temp log file: $!");
flock (TEMP, 2);
while (<LOG> ) {
chomp;
my @data = split /\|/, $_;
(($now - $data[1] > 600) or ($ip eq $data[0]) or (exists $ip{$data[0]})) and next;
$ip{$data[0]} = 4;
$count++;
print TEMP join("|", @data), "\n";
}
print TEMP join("|", ($ip, $now)), "\n";
close (TEMP);
close (LOG);
rename ("$log/temp.db", "$log/log.db");
print $count;

I use a standard SSI tag to call the script. It works as far as not giving any errors, just always shows 1.
thanks,
Paul
Webmaster Discussions
Quote Reply
Re: [hacker] Is this the problem In reply to
Problem I had and gave up on.

I tried this script out awhile back. It worked fine on one server and wouldnt work at all on another server.

They were both red hat 7.? and both supposedly set up properly (the working one I suspect would be the better of the two from those two hosts).

Fancy trying it again, can someone list the most up to date ssi and java code versions please?