vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Additional session variable: best way to store and retrieve? (https://vborg.vbsupport.ru/showthread.php?t=151048)

mfyvie 06-30-2007 04:03 PM

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)

Incendium 06-30-2007 09:24 PM

Why not use $_SESSION?

mfyvie 07-01-2007 05:35 AM

Quote:

Originally Posted by Incendium (Post 1280192)
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?

Dismounted 07-01-2007 06:14 AM

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.

mfyvie 07-01-2007 06:22 AM

Quote:

Originally Posted by Dismounted (Post 1280411)
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.


All times are GMT. The time now is 06:39 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.01418 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
  • (1)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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