View Full Version : Incrementing a counter for every page viewed
amykhar
12-11-2004, 05:26 PM
If I wanted to increment a counter every time a user (registered or not) viewed a page, what would be the best way to go about it?
Example, person hits the forumhome page. counter= 1. Person clicks a forum link and goes to the forum display page - counter = 2. Person clicks the link to go to the last post in a thread - counter = 3. Person goes back to forumhome page - counter = 4. And so on.
I'm just not sure the best way to carry the counter around without making it visible on the url, which I definitely don't want.
Thanks,
Amy
Boofo
12-11-2004, 05:33 PM
Do a table in the db and just run a query to add to the count on each page you want counted. I have a counter like that but only for my forumhome.
amykhar
12-11-2004, 05:46 PM
Do a table in the db and just run a query to add to the count on each page you want counted. I have a counter like that but only for my forumhome.
I'm wondering if there is any way to hook it into the session table, since that gets hit every time users do something anyway, right?
Boofo
12-11-2004, 05:48 PM
I'm wondering if there is any way to hook it into the session table, since that gets hit every time users do something anyway, right?
Should work. Let me know. I can save 2 queries on my forumhome if we can get it working that way. One to add and one to pull it. ;)
amykhar
12-11-2004, 06:35 PM
Well, this is weird. I added the column, and put in the counter. It works fine in Internet Explorer and in Firefox if I am logged out. But for some reason, if I browse while logged in with firefox, it's creating a new entry in the session table for every thing I do.
Amy
amykhar
12-11-2004, 06:48 PM
Well, this is weird. I added the column, and put in the counter. It works fine in Internet Explorer and in Firefox if I am logged out. But for some reason, if I browse while logged in with firefox, it's creating a new entry in the session table for every thing I do.
Amy
Well, nevermind on that one. It seems to only happen if the cookie path is set to a subdirectory, Which it won't be on the real live site.
So, it can be done from the session table.
1. add the pagecounter column
2. after the query in this section // check for session sent through URL/cookie
increment the pagecounter.
3. Make sure to change the modify and insert queries to include the pagecounter.
Saved two queries for ya, Bob. (But, you'll have to check the location if you only want it done on forumhome)
Amy
Boofo
12-11-2004, 07:12 PM
Well, nevermind on that one. It seems to only happen if the cookie path is set to a subdirectory, Which it won't be on the real live site.
So, it can be done from the session table.
1. add the pagecounter column
2. after the query in this section // check for session sent through URL/cookie
increment the pagecounter.
3. Make sure to change the modify and insert queries to include the pagecounter.
Saved two queries for ya, Bob. (But, you'll have to check the location if you only want it done on forumhome)
Amy
Can you send me the code you are using for all of this? I' did mine too long ago I guess. ;)
How did you pull it from the db without a query?
I think she used a query bob, just an existing database query instead of adding a new one :).
amykhar
12-11-2004, 07:34 PM
Can you send me the code you are using for all of this? I' did mine too long ago I guess. ;)
How did you pull it from the db without a query?
When I get the whole thing done, I'll release it. I'm not too far off now.
amykhar
12-11-2004, 09:24 PM
Here you go, Bob.
https://vborg.vbsupport.ru/showthread.php?p=581233#post581233
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.