![]() |
Session Page Views
Hi
Is there a variable I can use in the templates to see the number of page views for a user's current session? For example, user goes to the site and I want a banner at the top to display some promotion. After they have viewed a few pages I want it to go away and then would only return if they closed the browser and came back to start a new session. Thanks |
I don't know of such variable, but should be rather easy to make. I guess you can use the global hook and just make a new $_SESSION['pagecount'] variable and increment it on every page load.
|
I think that will work but I can't get it to increment:
$PageCount++; vB_Template::preRegister('header',array('PageCount ' => $PageCount)); The output is always 1. |
Not that I know what you are doing, nor would I probably do it this way.
But, if you were going to use @Dave's suggestion, you would have to store it in the superglobal for it to work. So maybe something like this: Code:
session_start(); |
I tried this in Global Start:
$PageCount = $_SESSION['PageCount']++; vB_Template::preRegister('header',array('PageCount ' => $PageCount)); Then in the Header Template I have this: Test {vb:raw PageCount} {vb:raw $PageCount} But I go not get any output, perhaps I need a different hook? I tried Global Complete also. Thanks |
I am not sure it is the right hook, I would have to look at it, but it should output.
Code:
session_start(); For testing purposes make sure it is not nested into a conditional, thus blocking output. {vb:raw PageCount} |
I did it like this:
Test {vb:raw PageCount} Test And do get Test output but not the number. I changed the code to what you put exactly but maybe it should be in someplace else. There is only 1 style. Thanks |
I tried the code on vb4.2.1, again, not that I would actually do it this way, but it worked the way I expected.
Change the hook to "parse_templates" for the most accurate count -- the count will still be off as I guessed. To test: set "PageCount = 'Test of Page Count'; (Some long string, not a number) Here is my test code: Code:
// Hook: parse_templates Out of suggestions for right now. |
Thanks, that hook worked.
|
All times are GMT. The time now is 07:10 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|