The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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.
|
#3
|
|||
|
|||
I think that will work but I can't get it to increment:
$PageCount++; vB_Template:reRegister('header',array('PageCount ' => $PageCount)); The output is always 1. |
#4
|
|||
|
|||
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(); $PageCnt = $_SESSION['pagecnt']++; |
#5
|
|||
|
|||
I tried this in Global Start:
$PageCount = $_SESSION['PageCount']++; vB_Template:reRegister('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 |
#6
|
|||
|
|||
I am not sure it is the right hook, I would have to look at it, but it should output.
Code:
session_start(); $PageCount = $_SESSION['PageCount']++; vB_Template::PreRegister('header',array('PageCount' => $PageCount)); For testing purposes make sure it is not nested into a conditional, thus blocking output. {vb:raw PageCount} |
#7
|
|||
|
|||
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 |
#8
|
|||
|
|||
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 session_start(); $PageCount = $_SESSION['PageCount']++; vB_Template::PreRegister('header',array('PageCount' => $PageCount)); Out of suggestions for right now. |
#9
|
|||
|
|||
Thanks, that hook worked.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|