PDA

View Full Version : Hit counters?


Major Attitude
07-06-03, 20:49
Anyone reccomend a good hit counter, preferrably Java or maybe CGI. No frills, just a count. Ive used quite a few and many reset at 5,000 and wont count higher. Thanks in advance, i need one for a website for a personal crusade of mine and being able to show visitors is VERY important to it.

iamien
07-06-03, 20:54
Gimmy like an hour. i'll code you a php one or something
I could make you a basic one real easy using a DB, its just the graphical output that would be a prob and i think i could get that sorted easy enough.
you need somethingg with style? or just soemthing funcational that wont reset
also i can make it use Session so that it wont just add everytime user refreash page, but they have to leave and what not

Major Attitude
07-06-03, 21:03
Functional that wont restart, I just need the numbers, ip logging can be there, but not required.... Thanks!

Ill have to check with Jim to see if a database is plugged in, I am still learning PHP\MySQL and am a major newbie, which is why i thought of Java or CGI..

iamien
07-06-03, 21:06
Alright well you'll need a DB
I'll make an class, so that all you'll have to do is include the file create an instance of the class set soem variables and palce where counter goes.
Bit tierd so might take little while but i need to make msyelf one anyway so this is just a better excuse :D
Thiss wil Require a MySQL Database as i dont know how towork with any other <but i assume Majorgeeks in run off MySQL anyway>
Anyway what i should have for you will be
You set
Text color
Background color
font size
define database informations
place the counter
Example of what it would be needed for you too do

<?
Include('counter.inc');
//initialize it
$counter = new counter;
$counter->bgcolor = "red" // or use hex
$counter->display() //would display it
?>

Should be simple nuff i shall be coding

Major Attitude
07-06-03, 22:02
Wouldnt it be easier to suggest a pre-written script?

iamien
07-06-03, 22:07
Dont have one :) i am makign this for msyelf if you want it you can use it as well.
If anyone knows a pre written one feal free hehe .

Kodo
07-06-03, 22:57
http://forums.devshed.com/archive/5/2000/06/4/4831

Major Attitude
07-06-03, 23:15
I have to check with Jim, theres a couple newer scripts that are cgi that might work. One inparticular is showing over 5,000 on their page, I think 5k is where it gets choked. Someone who knows Unix and perl might be familiar with this problem, I dont recall it exactly.

Njal
07-06-03, 23:16
I know you said java or cgi, but if you have php installed here is a little snippet that does exactly what you want. No frills, and no need for a database to drive it.

<?php
//
// Make a blank file called count.txt and CHMOD it 777
//
//Lets open the file as read only (r)
$fp = fopen("count.txt","r");
// The next line reads our file into a string,
// in other words sets the contents of count.txt as $count,
// so we can do stuff with it
$count = fread ($fp, filesize ("count.txt"));
// We don't need more data from the file right now, so close it
fclose($fp);
// Now we need to increment the number in the file, using the ++ operator, +1 would work but this is nicer.
$count++;
// Now we've incremented the count, lets write it to the file
// We need to open if for writing (w)
$fp = fopen("count.txt","w");
// Now write the actual data
fwrite($fp, $count);
// And close the file
fclose($fp);
// Lets display the updated count to the users
echo "Hits : $count";
?>

Major Attitude
07-07-03, 00:10
Thanks Njal, ill look into that, sup down there in Owsego? I ride my bike out Fulton way quite a bit lately...

Njal
07-07-03, 00:14
Not much in Ol' Oswego, the did thier 6th of July celebration tonight which was actually better than most years. Fulton from syracuse is a nice ride since 481 is in pretty good shape, out here they have just about ever road torn up and riding a bike through the construction wouldn't be much fun.

Just waiting now for HarborFest, I think its probably the only worthwhile thing to do in Oswego (unless you like military history then Fort Ontario isn't too bad).

Major Attitude
07-07-03, 08:04
Yeah, Harborfest is always a good time. Im in Bville, so a lot closer then Syracuse. Im actually about 3 miles from Oswego county line (Phoenix) so we usually tool up 57 or 48.

Vlad902
07-07-03, 19:23
Like the avatar, what *BSDs do you use?

Vlad902
07-07-03, 19:24
Originally posted by Njal

// Make a blank file called count.txt and CHMOD it 777


Bad idea, I would recommend for Apache module to change the user:group to nobody and chmod 600 it, for CGI interpeter just use 600

iamien
07-07-03, 22:00
heres what i made

is what it looks like (http://www.fritzsoft.net/php/count.php)
Fully customizable in size and colors you want? you can have it
just writing the documentation quickly be 5 min

iamien
07-07-03, 22:10
here ya go
first few lines of the file explain it

Vlad902
07-07-03, 22:11
Does it only take 1 hit from any IP, I just hit there several times and it didn't go to 91... chmod 444ing would give an fopen access violation bug, no?

iamien
07-07-03, 22:14
no its made to take only hit per session per user
IE untill you close all browser yo ucan refreash it.
Duno i jus trather be bale to track actual trafic, not how many times users can refreash a page

Philipp
07-09-03, 09:25
Using MySQL just for a hit counter is a wasting of resources, because each MySQL connection needs memory on the server.

Here a optimized (with file locking) version of Njal's counter script:

<?php
// Lets open the file as read/write (r+)
$fp = fopen("count.txt","r+");
// Now we lock the file for read/write access. The following
// lines will be only executed after the lock is positive.
if (flock($fp, 2)) {
// The next line reads our file into a string,
// in other words sets the contents of count.txt as $count,
// so we can do stuff with it
$count = fread ($fp, filesize ("count.txt"));
// Now we need to increment the number in the file, using the ++ operator, +1 would work but this is nicer.
$count++;
// Now we rewind $fp
rewind ($fp);
// Now write the actual data
fwrite($fp, $count);
// File locking end
}
// Here we remove the lock
flock ($fp, 3);
// And close the file
fclose($fp);
// Lets display the updated count to the users
echo "Hits : $count";
?>

Ive used quite a few and many reset at 5,000 and wont count higher.
This is usual caused by missing file locking (flock)

Major Attitude
07-09-03, 10:04
Trying that now, thanks Phillip and Njal. I had a bunch of scripts, many claiming flock was the problem with the option of having it on and off and they never seemed to work, but this should do.

iamien
07-09-03, 11:12
blast you php geek! Ahh nice one. To be honest i just made mine cause i wanted a class that i could expand to have Ip logging and browser type logging etc etc for what MA needs text file truley all thats needed heh

Major Attitude
07-09-03, 15:48
Well, yes and no, I would like to count unique ips, which isnt included in the latter. I may tinker more with yours, have not decided yet.

iamien
07-09-03, 18:47
at friends house atm, but i have a modified version of that class which does coutn IPs , goan make it check browser version then i'll post it

Major Attitude
07-09-03, 21:17
Cool by me! I am actually doing the site design now, nothing fancy, sites more about content, but Eric, who did our graphics, did one up for me that makes it look pretty cool.. Then I have to do a petition, probably a guestbook since I dont see any specific petition scripts.

Major Attitude
07-09-03, 22:50
Have a look at the test HTML in progress. Pretty much done, got to get counter working and add content and move to root. If anyone is aware of a petition script, please let me know. Thanks!


http://www.nohelmetlaw.com/test/

iamien
07-09-03, 23:28
what you you need in the script?
Just something where someone could add some info and then it would be entered into database, and a place too view everyone that has signed it?
shouldn't be very hard can do it if you give me specifications :)

Major Attitude
07-09-03, 23:52
Or log ips to a text file, whatever. Basically, for this site, the number of hits means nothing, i need to know visitors to give the site weight, you know? I dont care how it does it, for example, one ip per day would rock for the counter. With CGI, I have scripts to do that, but as mentioned, flock has always been a problem for me. I hate to get to a certain point and lose my count. Plus, PHP is easier on the server then a lot of GCI. Keep in mind I am aPHP newbie. Most of my skills are in HTML, CGI and Java. With PHP & MYSql, we have killer geeks like Phillips doing the backend and Jim doing some light editing. I mainly hang here, do files, answer emails and the such. Ill learn basic PHP one of these days though :)

Let me know and thanks again.... While your hear, thats a no on a prewritten petition script? I can use what I got, but was hoping someone knew of one already written...

Thanks again and again and again to everyone.

iamien
07-10-03, 22:06
Can't say i have ever truely looked for one. Having one IP per day can be easy with cookies.
I'll have some tiem tonight to set up a nice script for it and i'll make it simple as posible <IE a class> all you'll need to do is something like this

/* set up some color things> */
$somevar->update()

would be that simple to have the text file update realy.
you'd only need to tell it what the name of file is :P



Myself just learning HTML and CSS to be honest, . Sad i know more Php then i do HTML lol

Major Attitude
07-10-03, 22:21
I found a guestbook script and modified it. Really good script actually.

iamien
07-10-03, 22:42
Good job :D
hope you get law revokes, should have right to not wear if yo uwant.

Major Attitude
07-10-03, 22:49
Yeah, for every point, theres a counter point, its a long running debate, I am hoping to use the internet to get it more publicity and get New Yorkers together, up until now, its a few lobbyist and organizations scattered all over.

da chicken
07-10-03, 23:49
As far as helmet laws, I have no problem with people not wanting to wear them, but I think the state should encourage it. Maybe they should create a "no helmet" liscence... kind of an addendum to a motorcycle liscence. Basically just a permit, but the cost might help pay for costs resulting from severe injuries. (Severe accidents cost the state more than minor ones.) Also, one would assume it would act as a wavier of some kind to protect the state from prosecution (for allowing unsafe road conditions).

Your standard "I know this is unsafe, shut up, and leave me alone" kind of thing. Would you be willing to pay $20 a year for that?

Major Attitude
07-11-03, 22:13
Yup, I would. Problem is at anything beyond low speeds, helmets dont help. The DOT regulations are a joke dating back to 1966. Motorcyclists are insured and percentages are on par with motorcycle accidents. I can get you link and stats, as I said before, there is a point-counterpoint to any angle. In Florida, you need to carry and additional 10k insurance, problem is, naturally only a few insurance companies give them out. My favorite point is if someone believes in helmet laws so much, why are they not required in cars? Have you ever been to a junkyard and seen the windshields damaged with blood on them? The answer is because helmets are illegal in automobiles. Oddly enough, they claim they slow vision and hearing, yet on motorcycles, they like to quote studies that say they do not.

|AF|Titan
07-12-03, 17:56
1.Insert the following script in the <HEAD> section of your page

<SCRIPT language=JavaScript>
<!--
// Courtesy of SimplytheBest.net (http://simplythebest.net/info/dhtml_scripts.html)
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function ResetCounts(name)
{
visits = 0;
SetCookie("visits", visits, expdate , "/", null, false);
location.reload();
}
// -->
</SCRIPT>


2. Copy and save below code in the <BODY> section of your page where you wish the message to appear.

<SCRIPT language=JavaScript>
<!--
/*
It is brought to you by Eric Jarvies, Lewis Sellers, Giuseppe Lombardo, Kurt Anderson, and David Medinets.
*/
// Courtesy of SimplytheBest.net (http://simplythebest.net/info/dhtml_scripts.html)
var expdate = new Date();
var visits;
// Set expiration date to a year from now.
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
if(!(visits = GetCookie("visits")))
visits = 0;
visits++;
SetCookie("visits", visits, expdate, "/", null, false);
document.write("<center><STRONG>"+"Your browser has visited this page "+"</STRONG></center>"
+"<FONT COLOR=0000FF><center><STRONG>"+visits+"</STRONG></center></FONT>"
+"<center><STRONG>"+"time(s)."+"</STRONG></center>");
if(visits == 1)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+" Welcome to Simply the Best!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits == 2)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"Welcome back!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits == 3)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"Oh, it's you again!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits == 4)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"You like this script?" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits == 5)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"It's easy to use!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits == 6)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"Just follow the instructions!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits == 7)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"I'm sure you'll make it work!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits== 8)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"Good Luck!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits== 9)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"Good Luck!!!" +"</BLINK></STRONG></CENTER></EM></FONT>");
if(visits>=10)
document.write("<P><FONT SIZE=+2><EM><CENTER><STRONG><BLINK>"+"Good Luck!" +"</BLINK></STRONG></CENTER></EM></FONT>");
// -- End Hiding Here -->
</SCRIPT>




This script will count the number of visits and show a set of different messages every time the user accesses the page


Here is where it came from very cool site (http://www.simplythebest.net/info/dhtml_scripts.html)

Major Attitude
07-12-03, 19:31
My website does not currently load cookies on anyones computer. Looks too bloated for what I need.

|AF|Titan
07-12-03, 23:14
roger that :)

Major Attitude
07-13-03, 08:40
Dude, I will be seeing you in early October brother. Coming for the ride!