vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Session Page Views (https://vborg.vbsupport.ru/showthread.php?t=312749)

DRJ 07-06-2014 02:46 PM

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

Dave 07-06-2014 03:08 PM

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.

DRJ 07-06-2014 03:54 PM

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.

tbworld 07-06-2014 04:07 PM

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']++;

This will only work for your active session only.

DRJ 07-06-2014 04:26 PM

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

tbworld 07-06-2014 04:44 PM

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));

Make sure you are looking at the correct style.

For testing purposes make sure it is not nested into a conditional, thus blocking output.
{vb:raw PageCount}

DRJ 07-06-2014 05:20 PM

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

tbworld 07-06-2014 05:30 PM

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.

DRJ 07-06-2014 05:59 PM

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
  • Page Generation 0.01056 seconds
  • Memory Usage 1,722KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete