473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

visitor counter using cookie

Ben
Hi all,
This has been asked in the past in different ways. I'm still a bit
confused about setting up counters. I'm quite new to php. I've read
few tutorials about writing counters using cookie and sessions. It
sounds quite straight-forward. But what I'm unsure about is- if the
browser is set to accept cookies manually and the user blocks the
cookie, what happens? I think in that case, the counter is not
incremented because the value is not returned by the browser. Then we
are likely to get inaccurate counters. Is there a way to get
"accurate" counters?

Thanx
Ben
Jul 17 '05 #1
6 6289
Ben wrote:
Hi all,
This has been asked in the past in different ways. I'm still a bit
confused about setting up counters. I'm quite new to php. I've read
few tutorials about writing counters using cookie and sessions. It
sounds quite straight-forward. But what I'm unsure about is- if the
browser is set to accept cookies manually and the user blocks the
cookie, what happens? I think in that case, the counter is not
incremented because the value is not returned by the browser. Then we
are likely to get inaccurate counters. Is there a way to get
"accurate" counters?

Thanx
Ben


Hi Ben,

I think the articles did confuse you a bit. :-)
If you use a cookie for a visitorcounter, that counting only happens for
THAT visitor. But cookies can be important, read on.

You need to store somehow on the server how many visitors you have.

This can be done very easily by PHP using a plain simple file, or a
database.
If You are new to databases, I advise you to use a plain file, it is much
easier.

You just increase the counter every time a visitor calls a page on your
site.
This is often done by using a image that calls a PHP-script.

What about cookies?
What I describe above is not actually a visitorcounter: It is a
pagehitcounter.
If you want to count the number of unique visitors, you could use a cookie
for that.
This is how you do that:
1) If the countscript (possible the one that returns an image) is called, it
checks for the existance of a certain name set in the cookie.
eg "visitedalready"
1a) It is there: do nothing
1b) It is not there: set it in the cookie, and increase your counter by 1.

If cookies are disabled you could switch to SESSION-storage of that
"visitedalready".
The advantage is that Session will be build even if cookies are disabled.
This is done by url-rewriting, something like this:
phpscript.php?SESSIONID=asghdfhgasfdghasfdhgasfd

Hope that helps a bit.

Regards,
Erwin Moller
Jul 17 '05 #2
On Mon, 09 Aug 2004 05:19:28 -0700, Ben wrote:
Hi all,
This has been asked in the past in different ways. I'm still a bit
confused about setting up counters. I'm quite new to php. I've read
few tutorials about writing counters using cookie and sessions. It
sounds quite straight-forward. But what I'm unsure about is- if the
browser is set to accept cookies manually and the user blocks the
cookie, what happens? I think in that case, the counter is not
incremented because the value is not returned by the browser. Then we
are likely to get inaccurate counters. Is there a way to get
"accurate" counters?

Thanx
Ben

There's only one "reliable" way Ben, and that's logfile analysis. "Hit
counters" aren't worth the time they take to code (3 mins?).

If you have access to access_log, google for Webalizer and AWStats. AWS is
more complete in its analysis, but both are great tools.

An example of these 2 tools in action if interested:
<http://stats.web.digiserv.net/>
<http://aws.digiserv.net/awstats.pl?config=dsrc.digiserv.net>
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #3
Ian.H wrote:
On Mon, 09 Aug 2004 05:19:28 -0700, Ben wrote:


[ ... ]
Is there a way to get "accurate" counters?


There's only one "reliable" way Ben, and that's logfile analysis.


But don't equate server load with requests. Logfiles
indicate not requests, but server load. It isn't
practicable to count requests, nor useful to relay server
load statistics to end users.

--
Jock
Jul 17 '05 #4
On Mon, 09 Aug 2004 19:24:23 +0100, John Dunlop wrote:
Ian.H wrote:
On Mon, 09 Aug 2004 05:19:28 -0700, Ben wrote:


[ ... ]
> Is there a way to get "accurate" counters?


There's only one "reliable" way Ben, and that's logfile analysis.


But don't equate server load with requests. Logfiles
indicate not requests, but server load. It isn't
practicable to count requests, nor useful to relay server
load statistics to end users.

You've confused me John.. not requests?

My apache logs show nothing of server load (unless I tallied up concurrent
hits for each second of the day and then would be inaccurate.. what
about other services?).. but they do show requests, beit from a human and
browser or google etc.

The OP never mentioned whether this was to be private or publically
displayed values either.. displaying stupid counters to visitors is an
annoyance at best (most places that offer counters are also NULL-routed
here so any visits from myself would once again, cause inaccurate results).

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #5
Ian.H wrote:
On Mon, 09 Aug 2004 19:24:23 +0100, John Dunlop wrote:
But don't equate server load with requests. Logfiles
indicate not requests, but server load. It isn't
practicable to count requests, nor useful to relay server
load statistics to end users.
You've confused me John..


Sorry Ian.
not requests?
Requests don't necessarily reach the origin server, so
there's no feasible way to count them all. A request for a
resource might be fulfilled by a cache, whilst the origin
server is unaware of the transaction.

Jeffrey P. Goldberg's page on the subject is worth reading:
<http://www.goldmark.org/netrants/webstats/>.

[ ... ]
displaying stupid counters to visitors is an annoyance at best


Agreed; and in Mr. Goldberg's words, 'there are basically
two ways to put [counters] in your page: the wrong way and
the very wrong way'.

[ ... ]

--
Jock
Jul 17 '05 #6
On Mon, 09 Aug 2004 20:43:17 +0100, John Dunlop wrote:
Ian.H wrote:
On Mon, 09 Aug 2004 19:24:23 +0100, John Dunlop wrote:
> But don't equate server load with requests. Logfiles
> indicate not requests, but server load. It isn't
> practicable to count requests, nor useful to relay server
> load statistics to end users.
You've confused me John..


Sorry Ian.

No probs.. wasn't sure if I was reading things wrong or.... =)

not requests?


Requests don't necessarily reach the origin server, so
there's no feasible way to count them all. A request for a
resource might be fulfilled by a cache, whilst the origin
server is unaware of the transaction.

Ahh gotchya! Indeed and good point.

Jeffrey P. Goldberg's page on the subject is worth reading:
<http://www.goldmark.org/netrants/webstats/>.

Bookmarked for later reading =)


[ ... ]
displaying stupid counters to visitors is an annoyance at best


Agreed; and in Mr. Goldberg's words, 'there are basically
two ways to put [counters] in your page: the wrong way and
the very wrong way'.

[ ... ]

lol! I love it.

Thanks for the clarification John =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Song Zhang | last post by:
I have two webpage, one is http://appA.mycompany.com/first.html and the other is http://appB.mycompany.com/second.html When a user visits first.html, he may click a button A, which launches...
1
by: mahsa | last post by:
hi I have some asppage that have cookie and i want to use in in asp.net do you have any idea?
1
by: Mark | last post by:
I know I've seen an example of this, but can't seem to find it (I thought it was in my copy of 'ASP.NET Uleashed?). I want to use session_start in my global.asaax file to update a hit counter...
2
by: IloChab | last post by:
I'd like to implement an object that represents a circular counter, i.e. an integer that returns to zero when it goes over it's maxVal. This counter has a particular behavior in comparison: if I...
5
by: jasonchan | last post by:
How would you set up a counter in javascript that goes from 5 to 0 This is what i have so far and it is not displaying in the div container "counter" for some reason... <!DOCTYPE html PUBLIC...
3
by: W. Watson | last post by:
.... that is free for use without advertising that I can use on my web pages? I have no idea is suitable for this. My knowledge of Python is somewhat minimal at this point. Maybe Java is better...
5
by: vashafnas | last post by:
Hello all, I have an autologin feature in the login form.So if autologin selected once,it should work using cookies then.How to use it.Please help???
1
by: mikeh3275 | last post by:
I have a header control that I include in my .aspx page. In this control, I'm trying to retrieve a cookie value and store it into a string, but I am receiving an "Object reference not set to an...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.