1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is best way to persist data across web pages?

Discussion in 'XenForo Development Discussions' started by HeadHodge, Mar 13, 2015.

  1. HeadHodge

    HeadHodge 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.
     
  2. HeadHodge

    HeadHodge Member

    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???............
     
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    _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: Mar 16, 2015
    HeadHodge and thedude like this.
  4. Daniel Hood

    Daniel Hood Well-Known Member

    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.
     
    HeadHodge likes this.
  5. Sadik B

    Sadik B Well-Known Member

Share This Page