1

In PHP I can store values in a session I can get until it is destroyed / unset, Is this possible in jQuery or JS, too?

I need to store client side values to retrieve them in another page.

4
  • Do you back up your client code with a server? Please describe the setup of "another page" and "retrieving". Commented May 5, 2011 at 7:04
  • You cannot store values in session, you use a cookie to store. jquery also has cookie plugin using which you can store your values Commented May 5, 2011 at 7:10
  • I have created a comment system (php - jQ) and for example I use jQ cookies to mantain the admin panel opened (even at page reload or change) and even the Admin - logged in. ! Commented May 5, 2011 at 7:32
  • For now is in Croatian but look at the codes: A how to: JQ COOKIES Commented May 5, 2011 at 7:41

3 Answers 3

5

Use cookies or if you need to store lots of data and don't need compatibility with non-state-of-the-art browsers you could also use HTML5 localStorage.

Sign up to request clarification or add additional context in comments.

2 Comments

Html5 local storage... what about non-html-5 browsers? Can they handle this?
As I said, it's only supported by recent browsers.
2

There is nothing like a session variable directly available in javascript but there are definitely some alternatives to achieve this type of behavior. Two I can think of:

Javascript cookies

As demonstrated on this page you can create and retrieve cookies in javascript.

AJAX

You could use AJAX requests to set and retrieve your session variables from a php file. If you're not familiar with AJAX you can find some decent examples here for the classic javascript approach or in case of jQuery in the jQuery .ajax() docs. This method is probably more reliable because it doesn't depend on the client allowing cookies.

Comments

0

You can use JStorage plugin for this ,JStorage , jStorage makes use of HTML5 local storage where available and userData behavior in Internet Explorer older versions. Webkit SQLite is not supported.Current availability: jStorage supports all major browsers - Internet Explorer 6+, Firefox 2+, Safari 4+, Chrome 4+, Opera 10.50+ , (under 1kB when gzipped)!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.