Hit counters?

Discussion in 'Software' started by Major Attitude, Jul 6, 2003.

  1. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  2. iamien

    iamien Cptn "Eh!"

    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
     
    Last edited: Jul 6, 2003
  3. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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..
     
  4. iamien

    iamien Cptn "Eh!"

    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
    Code:
    <?
    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
     
    Last edited: Jul 6, 2003
  5. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    Wouldnt it be easier to suggest a pre-written script?
     
  6. iamien

    iamien Cptn "Eh!"

    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 .
     
  7. Kodo

    Kodo SNATCHSQUATCH

  8. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  9. Njal

    Njal Private E-2

    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";
    ?>
     
  10. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    Thanks Njal, ill look into that, sup down there in Owsego? I ride my bike out Fulton way quite a bit lately...
     
  11. Njal

    Njal Private E-2

    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).
     
  12. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  13. Vlad902

    Vlad902 Guest

    Like the avatar, what *BSDs do you use?
     
  14. Vlad902

    Vlad902 Guest

    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
     
  15. iamien

    iamien Cptn "Eh!"

    heres what i made

    is what it looks like
    Fully customizable in size and colors you want? you can have it
    just writing the documentation quickly be 5 min
     
  16. iamien

    iamien Cptn "Eh!"

    here ya go
    first few lines of the file explain it
     

    Attached Files:

    Last edited: Jul 7, 2003
  17. Vlad902

    Vlad902 Guest

    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?
     
  18. iamien

    iamien Cptn "Eh!"

    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
     
  19. Philipp

    Philipp Administrator Staff Member

    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:
    <?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($fp2)) {
    // 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 ($fpfilesize ("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 ($fp3);
    // And close the file
    fclose($fp);
    // Lets display the updated count to the users
    echo "Hits : $count";
    ?>
    This is usual caused by missing file locking (flock)
     
  20. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  21. iamien

    iamien Cptn "Eh!"

    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
     
  22. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  23. iamien

    iamien Cptn "Eh!"

    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
     
  24. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  25. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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/
     
  26. iamien

    iamien Cptn "Eh!"

    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 :)
     
  27. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  28. iamien

    iamien Cptn "Eh!"

    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
     
  29. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    I found a guestbook script and modified it. Really good script actually.
     
  30. iamien

    iamien Cptn "Eh!"

    Good job :D
    hope you get law revokes, should have right to not wear if yo uwant.
     
  31. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  32. da chicken

    da chicken MajorGeek

    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?
     
  33. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    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.
     
  34. |AF|Titan

    |AF|Titan Private E-2

    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
     
    Last edited: Jul 12, 2003
  35. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    My website does not currently load cookies on anyones computer. Looks too bloated for what I need.
     
  36. |AF|Titan

    |AF|Titan Private E-2

    roger that :)
     
  37. Major Attitude

    Major Attitude Co-Owner MajorGeeks.Com Staff Member

    Dude, I will be seeing you in early October brother. Coming for the ride!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds