• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Good MySQL Counter?

Ashed

New Member
Is there any counter out there that uses MySQL database and is something similar to this?

One that can count both hits for the day and hits in total would also be nice. :p

Yes, I've searched both HotScripts.com and PHP Resource Index. :)
 
Last edited:
if its not available in hotscripts it will prolly not come free
I would be able to write one for u for a fee
 
This one is pretty easy.
So you want a log file of number of hits of each day?
And a total number of hits for all the days?

Can you not use mySQL?
 
OK, I made one in perl. Maybe you like it?!?!?
Is rubbish for me. I just spent 10 mins on it.
All you have to do is define the log file directory where you use to store daily log. Make sure it is writable. Upload the script below in ASCII mode and CHMOD 0755.

On a normal web page, you must call my script to run. Example in SSI: <!--#exec cgi="/thescript.pl"--> Otherwise, you can't track the number of hits. It will show a number which is today hits.

Then call your script like that to see the daily and all hits:
http://www.yourdomain.com/thescript.pl?action=view_stat


Code:
#!/usr/bin/perl
use CGI qw(:standard :form);

####### CONFIG #######

$log_file_dir = qq(logs);

##### END CONFIG #####



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

$query = new CGI();
$action = $query->param('action');
if($action eq "view_stat") { &view_stat; }
else { &wr_daily_count; }

sub wr_daily_count {
	&all_count;
	$day_counter_file = "$log_file_dir/".sys_date();
	open(DAYCOUNTER, "$day_counter_file");
		$today_hits = <DAYCOUNTER>;
	close(DAYCOUNTER);
		$today_hits += 1;
	open(DAYCOUNTER, ">$day_counter_file");
		print DAYCOUNTER "$today_hits\n";
	close(DAYCOUNTER);
}

sub all_count {
	$all_counter_file = "$log_file_dir/all.count";
	open(ALLCOUNTER, "$all_counter_file");
		$all_hits = <ALLCOUNTER>;
	close(ALLCOUNTER);
		$all_hits += 1;
	open(ALLCOUNTER, ">$all_counter_file");
		print ALLCOUNTER "$all_hits\n";
	close(ALLCOUNTER);
}

sub view_stat {
	print qq(
	<HTML>
	<HEAD><TITLE>Yupapa Visitor Stats</TITLE></HEAD>
	<BODY>
	Yupapa Stats:<P>
	);
	chdir($log_file_dir);
	$counter = 0;
	foreach (<*>) {
		chomp;
		if(-f $_) {
			open(STATFILE,"$_");
			$stat = <STATFILE>;
			close(STATFILE);
			if($_ ne "all.count") {
				print qq($_ statistic: $stat<BR>);
			} else {
				print qq(<B>All Hits: $stat</B><BR>);
			}
			$counter++;
		}
	}
	if(!-f "all.count") { print qq(There is no statistic available); }
	print qq(
	</BODY>
	</HTML>
	);
}

sub sys_date {
	@days = ('1','2','3','4','5','6','7');
	@months = ('1','2','3','4','5','6','7','8','9','10','11','12');
	@en_month = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	$year = 1900 + $year;
	$month = $en_month[$mon];
	$today = "$month-$mday-$year";
	return $today;
}

__END__
 
Originally posted by GRiN
Is there any counter out there that uses MySQL database and is something similar to this?

One that can count both hits for the day and hits in total would also be nice. :p

Yes, I've searched both HotScripts.com and PHP Resource Index. :)
PM me, aim me at ejiant, or email me at elanb@removethispartbevcauseofspamhotpop.com.

I'm toying around with PHP, so I'll do it for free. Oh yeah, please add details. Do you want it to have daily logs or full blown stats?
 
Wow, thanks everyone for being so kind. :D

YUPAPA, I'll try that code and tell you whether it works or not. I heard that if you use text files to log the hits, it would just reset itself sometimes? So, I'm just testing out the SQL way to see whether it's going to be reliable or not.

agiantdwarf, I just need it to show the total hits and hits for the day and on another page showing the amount of hits for each day of the current month.
 
there is one in php and mysql at http://www.proxy2.de the site is down now for some reason but i have used it in past and it works great it also logs the ip address of the last 25 ppl in a small popup which u click on the counter and it shows up or u can disable that feature
 
Originally posted by triad web host
there is one in php and mysql at http://www.proxy2.de the site is down now for some reason but i have used it in past and it works great it also logs the ip address of the last 25 ppl in a small popup which u click on the counter and it shows up or u can disable that feature

Yeah, I tried that one but the visitors page only showed 1 address. :confused:

I'd like to try a few more, though. :D
 
Here is the mods... It is going to be two scripts.
One is for adding the number of hits and the other one is for viewing stats.

To put stats on your main page (SHTML), call it like that:
<!--#exec cgi="http://www.yourdomain.com/stats.cgi"-->

To count the hits, call the script like that:
<!--#exec cgi="http://www.yourdomain.com/counter.cgi"-->

Rembmer to edit the path and stuff between CONFIG and END CONFIG!

You can remove everything in the logs dir because they don't have anything to do with the following scripts

STATS.CGI
Code:
#!/usr/bin/perl

####### CONFIG #######

$log_file_dir = qq(logs);		# Directory where you store Logs (MUST BE WRITABLE)
$day_display = 10;				# Display number of days on the stats page

##### END CONFIG #####


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

print qq(
	Yupapa Stats:<P>
);
	$counter = 1;
	open(DAYCOUNTER,"$log_file_dir/daily.dat");
	while(<DAYCOUNTER>) {
		chomp;
		($day,$count) = split(/\|/, $_);
		$all_counter += $count;
		if($counter <= $day_display) {
			print qq($day statistic: $count<BR>);
		}
		$counter++;
	}
	close(DAYCOUNTER);
	if($counter == 1) { print qq(There is no statistic available); }

print qq(
	<P>
	All Visits: $all_counter
);

__END__


COUNTER.CGI
Code:
#!/usr/bin/perl

####### CONFIG #######

$log_file_dir = qq(logs);		# Directory where you store Logs (MUST BE WRITABLE)

##### END CONFIG #####


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

&wr_daily_count;

sub wr_daily_count {
	$day_counter_file = "$log_file_dir/daily.dat";
	open(DAYCOUNTER, "$day_counter_file");
		while(<DAYCOUNTER>) {
			chomp;
			($day,$count) = split(/\|/,$_);
			if($day eq sys_date()) {
				$today_hits = $count + 1;
				$saved_thing .= "$day|$today_hits\n";
				$found_record = 1;
			} else {
				$saved_thing .= "$_\n";
			}
		}
	close(DAYCOUNTER);
	open(DAYCOUNTER, ">$day_counter_file");
		if(!$found_record) {
			print DAYCOUNTER sys_date()."|1\n";
		}
		print DAYCOUNTER $saved_thing;
	close(DAYCOUNTER);
}

sub sys_date {
	@days = ('1','2','3','4','5','6','7');
	@months = ('1','2','3','4','5','6','7','8','9','10','11','12');
	@en_month = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	$year = 1900 + $year;
	$month = $en_month[$mon];
	$today = "$month-$mday-$year";
	return $today;
}

__END__
 
Back
Top