Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2007, 05:03 PM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Additional session variable: best way to store and retrieve?

I'm trying to store and reuse a value that should be valid for the entire session, whether a logged-in user or a guest. This value would then be available for use on any page loaded during that session.

Could someone perhaps point me to the most efficient way to do this? I started looking at the vB_Session class which seemed to have some promising methods, but then I realised that these are hard-coded for the existing fields in the session table.

Should I simply put something in the datastore? But if I put something in the datastore how will I be sure that it cleans out after the session expires? On re-reading the article about the datastore and taking a look at it, it appears that it isn't really designed for storing data associated with a session.

I apologise if this sounds like I'm asking too many questions - but I have been reading through the vB code documentation and various tutorials all day. This is sort of along the lines of what I want:

at global_start:

Code:
if (!isset($userinfo['foo'])) {
    $userinfo['foo'] = "Our value to remain for the entire session";
    // now we need to save it somehow so when the next page
    // is loaded it is still here, and this conditional doesn't execute again
}
Any help would be greatly appreciated! (this question is unrelated to my other thread about adding a field in the admincp by the way)
Reply With Quote
  #2  
Old 06-30-2007, 10:24 PM
Incendium Incendium is offline
 
Join Date: Apr 2004
Location: Dallas, TX
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why not use $_SESSION?
Reply With Quote
  #3  
Old 07-01-2007, 06:35 AM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Incendium View Post
Why not use $_SESSION?
I wondered about this, but when I did a grep through the vbulletin files, I couldn't find a single occurrence of $_SESSION. I know the vbulletin code standards tell us not to use superglobals like $_POST, $_GET, etc, so is using $_SESSION somehow a bad thing? Is there a better way, and how does vb do it?
Reply With Quote
  #4  
Old 07-01-2007, 07:14 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

vBulletin adds things to the session table. Note "inforum", etc. Just insert a field into that table and update it, vBulletin will handle the cleaning up. They are then accessed via $vbulletin->session->vars.
Reply With Quote
  #5  
Old 07-01-2007, 07:22 AM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dismounted View Post
vBulletin adds things to the session table. Note "inforum", etc. Just insert a field into that table and update it, vBulletin will handle the cleaning up. They are then accessed via $vbulletin->session->vars.
Yes, I did look at the session table and the various mechanisms initially, but wondered if I would be adding too much overhead by extending the session table. But I guess you are right, it is the most efficient way to do it, and since this table gets cleaned up, I guess it's the right way to go.

I just wanted to make sure I do this in the most efficient way possible. Thanks for the tip.
Reply With Quote
Reply


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 03:10 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.03707 seconds
  • Memory Usage 2,197KB
  • 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
  • (1)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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