Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 11-04-2015, 12:34 PM
ub.ch ub.ch is offline
 
Join Date: Jul 2010
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default (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
Reply With Quote
  #2  
Old 11-04-2015, 12:56 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A better way is to keep the search term in the URL (a $_GET parameter). Have you considered that?
Reply With Quote
  #3  
Old 11-04-2015, 02:05 PM
ub.ch ub.ch is offline
 
Join Date: Jul 2010
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yep I have, but it is multiple keywords / checkboxes and I don't want to "clutter up" the URL that way
Reply With Quote
  #4  
Old 11-04-2015, 02:20 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could serialize those variables and put them in the URL in 1 parameter.
You could also base64_encode it.
Reply With Quote
  #5  
Old 11-04-2015, 02:42 PM
ub.ch ub.ch is offline
 
Join Date: Jul 2010
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 11-04-2015, 02:57 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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');
Reply With Quote
  #7  
Old 11-04-2015, 09:13 PM
ub.ch ub.ch is offline
 
Join Date: Jul 2010
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Dave!
How would I read them? Just using $_COOKIE / $_SESSION?
Reply With Quote
  #8  
Old 11-05-2015, 06:32 AM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 11-05-2015, 10:27 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is a vB page? Then do it the proper vB way. https://vborg.vbsupport.ru/showthread.php?t=221670
Reply With Quote
  #10  
Old 11-06-2015, 11:07 AM
ub.ch ub.ch is offline
 
Join Date: Jul 2010
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks for your help!!

Quote:
Originally Posted by Dave View Post
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 View Post
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
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 01:50 PM.


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.09862 seconds
  • Memory Usage 2,244KB
  • 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
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete