What is best way to persist data across web pages?

HeadHodge

Active member
I'm creating an add-on that contains information I would like to persist between multiple pages from the users web browser.

I've been studying the cookies that xenforo uses for statefulness and I'm confused. When at I look at a submit form, it uses _xftoken, in the header cookie there is also xf_session, and when searches are performed there is a searchid that is used to page through search results.

So for my data, what is the recommended way to persist data across multiple pages?

I've successfully used in my controller the Xenforo_Session "get session" function, the "set session key" function, and the "save session" function across multiple pages. But I'm not sure if that's the way to go because I don't understand the other cookies being passed from the browser to the controller. Especially the _xftoken.
 
Thanks for the few replies I've received, but I find the participation here to really be underwhelming. :(

So, I'll answer my own question (based on the typical replies I read here).

Answer: Read all the xenforo code and the answer will then become obvious to even the most casual observer. o_O

Thanks???............
 
_xfToken is just a "token" to prevent CSRF http://en.wikipedia.org/wiki/Cross-site_request_forgery

To persist data across multiple page visits for a visitor with the same session, XenForo_Session object would be your best bet.

You can access into the object by calling
PHP:
XenForo_Application::getSession();

Do note that you can only save data from a controller and after the dispatch the session object becomes "read-only" ;)

P.S. Look into XF's source for more info :p
 
Last edited:
Can also use cookies.

Code:
XenForo_Helper_Cookie::setCookie()

Code:
XenForo_Helper_Cookie::getCookie()

Look at /XenForo/Helper/Cookie.php for the exact parameters to use and set.
 
Top Bottom