vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   (temporarily) save data to cookie or session (https://vborg.vbsupport.ru/showthread.php?t=320703)

ub.ch 11-04-2015 12:34 PM

(temporarily) save data to cookie or session
 
Heya!

I built a plugin with a search in it, which I want to paginate.
The easiest way in my mind was to save the search term(s) either into a session or a cookie and then, when page two is requested, do the search query again.

Now I can't seem to be able to access either cookies or session.
Tried using $_SESSION or $_COOKIE or vbsetsession() but to little avail it did not work :(

Any recommendations on how to properly do this?

Any help is really appreciated :)

ps: with "not working" I mean, that I can write to either, but after reloading the page, the information is no longer saved

Dave 11-04-2015 12:56 PM

A better way is to keep the search term in the URL (a $_GET parameter). Have you considered that?

ub.ch 11-04-2015 02:05 PM

Yep I have, but it is multiple keywords / checkboxes and I don't want to "clutter up" the URL that way

Dave 11-04-2015 02:20 PM

You could serialize those variables and put them in the URL in 1 parameter.
You could also base64_encode it.

ub.ch 11-04-2015 02:42 PM

yep I know I could do this, but don't want to ;)
That would be the last resort; second to last would be to resend the form on every page change - but still, the question is: how can I use vbulletin sessions or cookies

Dave 11-04-2015 02:57 PM

Alright well in order to set a session variable, you can use $vbulletin->session->set('key', 'value');
For cookies you want to use vbsetcookie('key', 'value');

ub.ch 11-04-2015 09:13 PM

Thanks Dave!
How would I read them? Just using $_COOKIE / $_SESSION?

Dave 11-05-2015 06:32 AM

I believe you can use $vbulletin->session->vars['key'] to access the session variable.
You can just use $_COOKIE['key'] to access the cookie value.

cellarius 11-05-2015 10:27 AM

This is a vB page? Then do it the proper vB way. https://vborg.vbsupport.ru/showthread.php?t=221670

ub.ch 11-06-2015 11:07 AM

thanks for your help!!

Quote:

Originally Posted by Dave (Post 2558263)
I believe you can use $vbulletin->session->vars['key'] to access the session variable.
You can just use $_COOKIE['key'] to access the cookie value.

mhh can't get both of them to work :(
I can save to the session, but refreshing the page yields no data.
Cookies are not working at all :/

Quote:

Originally Posted by cellarius (Post 2558266)
This is a vB page? Then do it the proper vB way. https://vborg.vbsupport.ru/showthread.php?t=221670

I will have a look into it, still does not solve the problem I actually have.
I _don't_ want to have $_GET params; the page you linked to has actually no keywords or params to be searching for. Or am I missing something?

If I get it to work, I would still like to know how to save data to the session / cookie ;)


All times are GMT. The time now is 09:41 AM.

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.03122 seconds
  • Memory Usage 1,726KB
  • 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
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete