webForumDet fria alternativet

Varför funkar inte det här?

0 svar · 129 visningar · startad av axel n

axel nMedlem sedan jan. 20017 inlägg
#1

Jag har hittat ett script som ska räkna hur många aktiva besökare det är på sidan. Men om om en person går in på sidan så måste nästa person som går in på sidan gå in 1 sekund efter den andra för att det ska stå 2 aktiva besökare, går han in 2 sekunder efter den första så står det 1 aktiv besökare. Det här blev lite klöddigt men jag hoppas att nån förstår.

guests.pl

#!/usr/bin/perl 

##############################################################################
# Guests v1.2
# Copyright (c)1999 Ryan Lambert, All Rights Reserved.
#
# Created: 5/25/1999
# Last Modified: 6/23/1999
#
# Email Support: ral@bitsmart.com
# Web Site: [url="http://www.bitsmart.com/ral/"]http://www.bitsmart.com/ral/[/url] 
##############################################################################
# Define Variables

	# The file that stores IP addresses and time they accessed the site
	$guests_data = 'guests.txt';

	# How many seconds to keep an IP address in the list before it becomes invalid
	$timeout = 25;

	# Logs at what time you had the most guests browsing your site
	$max_log = 'maxguests.txt';

# Done! No need to go below unless you know what your doing!
##############################################################################

	$line = $ENV{'REMOTE_ADDR'} . "\t" . time . "\n";

	print "Content-type: text/html\n\n";

	if ( -e $guests_data ne 1 or -s $guests_data eq 0 ) { &write_new; print '1'; exit; }

	&write_update;

	&write_new;

	$count = &read_count;

	print $count;

	&log_max if $max_log;

	exit;

##############################################################################
# Sub-Routines

sub log_max
{
	if ( -e $max_log )
	{
		open(FILE,$max_log) || die $!;
		$log = <FILE>;
		close(FILE);
	}
	else { $log = "0\t0" }
	
	($MAX,$TIME) = split(/\t/,$log);
	
	if ( $count > $MAX )
	{
		($sec,$min,$hour,$mday,$mon,$year)=localtime(time);
		$year = $year + 1900;

		open(FILE,">$max_log") &#0124;&#0124; die $!;
		print FILE "$count\t$hour:$min:$sec $mon/$mday/$year";
		close(FILE);
	}

}

sub read_count
{
	open(FILE,$guests_data) &#0124;&#0124; &error;
	@file = <FILE>;
	close(FILE);

	$count = @file;

	return($count);
}

sub write_new
{
	open(FILE,">>$guests_data") &#0124;&#0124; &error;
	print FILE $line;
	close(FILE);
}

sub write_update
{
	open(FILE,$guests_data) &#0124;&#0124; &error;
	@file = <FILE>;
	close(FILE);

	open(FILE,">$guests_data") &#0124;&#0124; &error;
	foreach $fline ( @file )
	{
		($IP,$TIME) = split(/\t/,$fline);
		chomp($TIME);
		if ( $IP ne $ENV{'REMOTE_ADDR'} )
		{
			if ( $TIME + $timeout > time ) { print FILE "$IP\t$TIME\n"; }
		}
	}
	close(FILE);
}

sub error
{
	print "[Unexpected error ocurred]";
	exit;
}

# End of sub-routines. End of script. All done.
##############################################################################
126 ms totalt · 3 externa anrop · v20260731065814-full.3ab8d573
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
123 ms — hämta tråd, inlägg och bilagor (db)