How to save session values in JavaScript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Feb 2005
Posts: 3
Reputation: omnis is an unknown quantity at this point 
Solved Threads: 0
omnis omnis is offline Offline
Newbie Poster

How to save session values in JavaScript

 
0
  #1
Feb 26th, 2005
How do you save a session value in JavaScript?

Please help!
Sally
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: How to save session values in JavaScript

 
0
  #2
Feb 26th, 2005
Use cookies. google it with javascript and cookies. There are a ton of functions for it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 6
Reputation: nemo5 is an unknown quantity at this point 
Solved Threads: 0
nemo5 nemo5 is offline Offline
Newbie Poster

Re: How to save session values in JavaScript

 
0
  #3
Dec 31st, 2006
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function createCookie(name,value,days) {
  2. if (days) {
  3. var date = new Date();
  4. date.setTime(date.getTime()+(days*24*60*60*1000));
  5. var expires = "; expires="+date.toGMTString();
  6. }
  7. else var expires = "";
  8. document.cookie = name+"="+value+expires+"; path=/";
  9. }
  10.  
  11.  
  12. function readCookie(name) {
  13. var nameEQ = name + "=";
  14. var ca = document.cookie.split(';');
  15. for(var i=0;i < ca.length;i++) {
  16. var c = ca[i];
  17. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  18. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  19. }
  20. return null;
  21. }
  22.  
  23. function eraseCookie(name) {
  24. createCookie(name,"",-1);
  25. }



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.
For a man without a destination no wind is favourable

http://www.vydavatelstvo-f.sk
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC