Click to See Complete Forum and Search --> : visitor counter
-manu-
March 22nd, 2002, 07:32 AM
Hi gurus
I have an HTML file on a directory.
Many people can access to that file from their computers, and i would like to have a visitor counter.
I've found something using cookies but it will tell the users how many times they open the file, not how many times the file was open (by them or others users).
Any idea ?
I have to say i don't know a thing about html and JavaScript.
Thanks
bon bah tsho
manu
hugo123
March 25th, 2002, 04:33 AM
You can use javascript with cookie for that. I take this code from the documentation.
The fonction register can set cookie:
function register(NbVisit)
{
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie("TheCoolJavaScriptPage", NbVisit, expires)
}
the functions setCookie and getcookie are :
function getCookie(NbVisit)
{
var search = NbVisit + "="
if (document.cookie.length > 0)
{ // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1)
{ // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
function setCookie(NbVisit, value, expire)
{
document.cookie = NbVisit + "=" + escape(value)
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
However if you really didn't know html and javascript, you can use a counter given by some sites. You just have to add a piece of code in your page. (not personnal counter, but global counter).
In this forum you can find a link for the javascript manual, it can help you.
-manu-
March 25th, 2002, 06:17 AM
Hi
Thanks but i think that your solution is not good for my problem : since you use cookies, it is client dependent, and it will only give me the number of times the client visited the page.
This is not what i want.
Thanks anyway.
bon bah tsho
manu
hugo123
March 25th, 2002, 07:34 AM
Maybe I didn't understand what you want. I thought that you want to display the number of visit for each client.
Can you precise your question?
-manu-
March 25th, 2002, 07:38 AM
I want the total number of times this page was open, whoever opened it
In french : je veux le nombre total de fois que mon fichier a été ouvert, et pas le nombre de fois que l'utilisateur X l'a ouvert (ce que me donnerait un compteur basé sur des cookies). Comme un compteur classique sur une page web, en fait, sauf que sur une page web c'est le serveur lui-même qui fait le compte, et que moi je gère un simple fichier html. Merci.
bon bah tsho
manu
hugo123
March 25th, 2002, 10:34 AM
Sorry, I don't know how to do that with javascript, but I'm not a expert. Since javascript is client side, I don't know how you can retrieve the total number of times the page was open.
Ps: just for Manu:
Salut,
J'essayais de répondre à ta question dans le forum javascript et je viens de me rendre compte que c'est toi qui m'a aidé l'année dernière pour mon stage. (Dans tes anciens post dans le forum VC++ tu peux voir hugo123, c'était moi. :))
En tout cas ton aide m'avait été bien précieuse l'année dernière. Je suis maintenant en stage de dernière année. Bonne continuation a+
Brad Jones
April 2nd, 2002, 08:37 PM
You can't do overall tracking of all people visiting a site on the client (HTML and JavaScript). You'll need to use a server-side control, ASP, or some other server side code. There are several Web sites that provide this functionality. http://www.TheCounter.com is one such site (which happens to be owned by the same company as CodeGuru.com).
- Brad!
Site Manager, CodeGuru.com
Check out my newest book (Sams Teach Yourself C# in 21 Days):
http://books.internet.com/books/0672320711
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.