Solved

hit counter for htm page (NO DB)

Posted on 2004-09-16
28
393 Views
Last Modified: 2008-02-26
Hi Experts,

how do i create a hit counter on my htm page, but i do not have a database even access. I can not use webcomponent from frontpage, because of extension problem. I would like to see a sample code for it. I know there are many website out theter to do that, but i like to have that in my machine.

thank you all
0
Comment
Question by:shibut
  • 8
  • 8
  • 4
  • +3
28 Comments
 
LVL 5

Expert Comment

by:apparition
ID: 12074531
You can sign-up for a counter with an external site, and provide you with the sample HTML to put on your
page for the counter to work. Here are some sample links

http://www.robocounter.com/
http://freelogs.com/
http://www.statcounter.com/free_hit_counter.html
http://gostats.com/
http://easy-hit-counters.com/
0
 

Author Comment

by:shibut
ID: 12074575
I do not want to sign-up for counter, but i like to have the code. I do not want my site on their server.
0
 
LVL 5

Accepted Solution

by:
apparition earned 68 total points
ID: 12074628
Your site will not be on their server only the counter will be on their server.
0
 
LVL 5

Expert Comment

by:apparition
ID: 12074650
If you want try Javascript. Code from : http://webdeveloper.earthweb.com/webjs/cookies/item.php/25101
<HTML>
<HEAD>
      <TITLE>Javascript Counter v1.0</TITLE>
      <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- By David Hyman -->            
<!-- Hide script from older browsers
      
          expireDate = new Date
          expireDate.setMonth(expireDate.getMonth()+6)
            hitCt = eval(cookieVal("pageHit"))
            hitCt++
            document.cookie = "pageHit="+hitCt+";expires=" + expireDate.toGMTString()
            
            function cookieVal(cookieName) {
                  thisCookie = document.cookie.split("; ")
                  for (i=0; i<thisCookie.length; i++) {
                      if (cookieName == thisCookie[i].split("=")[0]) {
                            return thisCookie[i].split("=")[1]
                      }
                   }
                  return 0
            }

            // End hiding script -->
      </SCRIPT>      
</HEAD>
<BODY BGCOLOR=WHITE>
<H2>
      <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
            <!-- Hide script from older browsers

            document.write("You have visited this page " + hitCt + " times.")

            // End hiding script -->
      </SCRIPT>
</H2>
</BODY>
</HTML>
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12074694
Heres a basic php hit counter:

<?php
$file = "/path/to/counter/file/hitcount.txt";
$len = 6; //numbers to display (for padding)

$count = @file_get_contents($file);
if (empty($count)) $count = 1;
$count = sprintf('%0'.$len.'u', $count);
$handle = fopen($file,"w");
fwrite($handle, $count+1);
fclose($handle);

echo $count;
?>

Your files extension must be .php (as opposed to .htm or .html) and you must have php installed on your server.
The hit counter file also must have write access so chmod 666
0
 

Author Comment

by:shibut
ID: 12074839
hello apparition,
I do not want to distinguish any visitor, it does not matter who hit the website, just add to that number, i need the total visitor to that site. If i have cookies in, it will seperate each user.
thank you.
0
 

Author Comment

by:shibut
ID: 12074851
I have a .htm extension, i do not want to change it to .php
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12074866
If its your own server you can configure it to parse htm files for php content so you wouldnt have to rename the extension.
0
 

Author Comment

by:shibut
ID: 12074888
its not my server
0
 
LVL 1

Expert Comment

by:sheheryarjaved
ID: 12075036
shibut if you know xml using javascript than use a single node and onload retrive data from it and update by incrementing 1
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12075046
The problem is client side languages are very limited, in order to use a hit counter in manor that you want you must be able to write to a file, or update a database stored on the server. JavaScript cannot do this as it is strictly client side.

Most server side languages by default require a specific file extension which indicates that that file must be parsed, without the ability to change which extensions are parsed and not wanting to rename your files extension you might find yourself a little stuck.
0
 
LVL 1

Assisted Solution

by:sheheryarjaved
sheheryarjaved earned 66 total points
ID: 12075088
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Expert Comment

by:apparition
ID: 12075100
sheheryarjaved ,

thats the same solution I suggested.
0
 
LVL 1

Expert Comment

by:sheheryarjaved
ID: 12075204
i am sorry did saw it really.
0
 

Author Comment

by:shibut
ID: 12075235
from my understanding, cookies will store all the location, so do we able to add all numbers in it. then we can find out total number of visitor's in it. and do we able to print out all the cookie's name and total number in it. then we can use that solution guys.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12075306
Cookies are client side, they are stored in the users computers so you cannot produce a total count this way. As i said you will not be able to have a hit counter depending on client side languages.
0
 

Author Comment

by:shibut
ID: 12075395
Diablo, I have hundreds of htm pages in the server so do i able to just configure one htm page with php extension. If yes, then how do i do it
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12075462
If you want the counter functional on every page of your site then they will all need the .php extension, this would be impractical i would imagine. If you only want the counter functional on one page then you only need to rename that one files extension to .php.

The ideal thing would be configuring the web server to parse .htm extensions but as you have said its not your server so this is sadly not possible.

To be frank i think your best bet would be having the counter remotely hosted using a site that provides the feature like freelogs.com. Then all you will need is a small snippet of code to paste on your site and everything else is handled on their server without you having to worry about it.
0
 

Author Comment

by:shibut
ID: 12075540
if i use threir server, how does it work probably some add like pop up. Like privacy. They have to do something to make. There are no free lunch as you know. Do you hAVE ANY  IDEA ABOUT THAT. THANK YOU
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 66 total points
ID: 12075746
According to their FAQ there are links included in the counter code (which you could technically remove but this would violate the agreement i expect). I assume the link will link back to their site to promote their service, sadly nothing is completely free in this world.

I have just thought though, you *might* be able to work around the problem using a CGI script instead, i don't think you need to rename the extensions for this. Personally i don't like the perl language or cgi so i tend to forget it exists however matts script archive has a little script for this.

http://www.scriptarchive.com/textcounter.html

As i said im not one for CGI so as for setting it up im not so sure about but their is a readme file included in the download. I would imagine it entails putting the script in the CGI-BIN or something similar.

Anyway to link to the counter all you need in your page is something like: <!--#exec cgi="/virtual/path/to/counter.pl"-->

It might be worth a look as an alternative to having to have links or anything in a remotely hosted script.
0
 

Author Comment

by:shibut
ID: 12077795
i'am working on it now.
0
 
LVL 2

Expert Comment

by:harveykane
ID: 12078300
Another option not mentioned yet is that "most" ISPs / Server operators have a standard CGI based counter script they make available for sites they host. Instructions vary on how to configure them.

This should be the first thing to check, and if they don't provide one, see if it's a big deal for them to install one.
0
 
LVL 1

Expert Comment

by:Alexmipego
ID: 12079251
Hi,

do you have access to the raw log files?
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12514050
As shibut did not post back i assume s/he got it working successfully in which case my recommendation is accept my comment http:Q_21133467.html#12075746
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12960557
hmm.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now