Gossamer Forum
Home : Products : Links 2.0 : Customization :

visitors online = ?

(Page 1 of 2)
> >
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.

> >