Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
  #1  
Old 07-06-2014, 02:46 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 07-06-2014, 03:08 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 07-06-2014, 03:54 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 07-06-2014, 04:07 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 07-06-2014, 04:26 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 07-06-2014, 04:44 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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}
Reply With Quote
  #7  
Old 07-06-2014, 05:20 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 07-06-2014, 05:30 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 07-06-2014, 05:59 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, that hook worked.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:07 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03997 seconds
  • Memory Usage 2,227KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete