Use cookies. google it with javascript and cookies. There are a ton of functions for it.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
There are more ways to do it than just cookies - it basicaly depends if you want to store the session between visits that happend at the same time, or if you want to save sessions for later use.
If the later is what you want, go for cookies:
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
If you just want to save the session while the user leaves your pages you could use a hidden frame and store the session value inside a hidden input.
javascript only support cookies. You can set them up to keep track of a user session but they do not support the use of sessions. PHP uses both sessions ans cookies. If you trying to pass in session variables from PHP to Javascript you will have to come up with a good work around since there is no direct way to do this. you can use hidden fields that generate the variable which you can then get in javascript.
wrivera
Junior Poster in Training
53 posts since Jan 2010
Reputation Points: 10
Solved Threads: 10