![]() |
(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 |
A better way is to keep the search term in the URL (a $_GET parameter). Have you considered that?
|
Yep I have, but it is multiple keywords / checkboxes and I don't want to "clutter up" the URL that way
|
You could serialize those variables and put them in the URL in 1 parameter.
You could also base64_encode it. |
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 |
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'); |
Thanks Dave!
How would I read them? Just using $_COOKIE / $_SESSION? |
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. |
This is a vB page? Then do it the proper vB way. https://vborg.vbsupport.ru/showthread.php?t=221670
|
thanks for your help!!
Quote:
I can save to the session, but refreshing the page yields no data. Cookies are not working at all :/ Quote:
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 ;) |
You can add as many get-parameters as you need to this method. See the Constructing pagenav section.
Anyway, that's not what you want, then. Although I don't quite understand why you would want to hide away the search parameters. I find that highly annoying as a user, since search results can't be linked to (like in vb with it's cached searches). In my opinion, there's good cause why for example Google does not do that. |
All times are GMT. The time now is 02:04 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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|