Forum Moderators: open

Message Too Old, No Replies

Logged in automatically next time you visit

javascript newbie question...

         

John_Caius

6:04 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simple question, hopefully simple solution. :)

I've got users able to login on my site and use restricted features. How can I use a javascript cookie to have them automatically logged in next time they visit?

Thanks...

John_Caius

12:23 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...or are there other simple ways to do this other than with a javascript cookie?

Rambo Tribble

1:15 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cookies are accessible through JavaScript or server-side scripts. Either should allow for what you are doing. Be aware, however, that cookies aren't terribly secure.

John_Caius

1:44 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Security's not too much of a concern with what we're doing on the site - no credit card details or anything. This is just for a user accessibility option - exactly the same as what WW does.

Do you know of an online tutorial that says how to do it? When I search Google for [javascript tutorial "remember me"], I just get a load of sites with a "remember me" tickbox on their own login form, not an explanation of actually how to do it!

Rambo Tribble

3:08 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know of anything online, but the O'Reilly books, JavaScript: The Definitive Guide and Designing With Javascript, both have good descriptions of cookies, their components and manipulating them in JavaScript.

If you're using Mozilla or one of its siblings, Tools - Cookie Manager - Manage Stored Cookies will allow you to view the cookies the browser has stored. Investigating that may help you to visualize the data and format of a cookie.

Basically, cookies are just text strings. document.cookie is a concatenated string that stores all the cookies for a domain. A domain may have 20 individual cookies, each no larger than 4K. To manipulate an individual cookie you assign document.cookie's value to a variable, then use a string search to find the specific cookie, then string parsing techniques to process it.

You should be aware that the latest implementations of the W3C's P3P policy have resulted in cookies becoming more restricted. You may wish to investigate creating a security policy for your site before you try setting cookies on users' machines. This is a good place to begin that oddessy, [p3ptoolbox.org...]

John_Caius

11:02 am on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for those pointers - the website makes useful reading.

Is there anyone else with a site with a login section who can explain briefly how to do this long term cookie thing?