944,145 Members | Top Members by Rank

Ad:
Feb 21st, 2006
0

log in script saves cookie

Expand Post »
Im after a way to code the following login script in javascript.
The login menu is a dropdown offering "log in for"~ select "x"minutes, hours, forever etc.

not sure if its possible in javascript?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aperson is offline Offline
4 posts
since Feb 2006
Feb 21st, 2006
0

Re: log in script saves cookie

You can certainly write cookies with JavaScript, yes. A simple web-search should reveal hundreds of examples. You can also use the JavaScript "timer" object to periodically check to see if a cookie has expired. So yeah, this could be done. However, it won't be secure.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Feb 22nd, 2006
0

Re: log in script saves cookie

Quote originally posted by tgreer ...
You can certainly write cookies with JavaScript, yes. A simple web-search should reveal hundreds of examples. You can also use the JavaScript "timer" object to periodically check to see if a cookie has expired. So yeah, this could be done. However, it won't be secure.
Could somebody actually help me with a code for this. The idea is to create a dropdown login menu, with options like "log in for 30 mins" log in for 1 hour" log in for x hours" login forever(which would be virtually an autologin by ip. cookie stores ip and keeps your session neverending bascially?
can this be done?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aperson is offline Offline
4 posts
since Feb 2006
Feb 22nd, 2006
0

Re: log in script saves cookie

Yes, it can be done, using the techniques I've already described. What specifically have you tried? At what point does it fail? You need to show us what you've already tried, what you already know, so we can help you properly.

As I said, there are lots of examples of how to read/write cookies with JavaScript, and the other object you'll need is the "timer" object.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Feb 23rd, 2006
0

Re: log in script saves cookie

Sorry, I did not make myself clear. I have been reading up about cookies, I can understand the principles behind how they work, however Im totally new to actually writing code, Im afraid I cant string 2 variables together for trying. I did try a cookie script but It didnt do anything at all. What Im asking is if you could please draft something like this, explaining where I should add/modify parts so I can work from it. I havent been able to find examples of such a cookie script.
Im just asking for an example roughly suited to the purpous I want, Ie to remain active session, so when a member closes the browser, they are not logged off but can return later (if not indefinate period atleast up to a few days later) and still be logged in provided they dont delete their own cookies. ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aperson is offline Offline
4 posts
since Feb 2006
Feb 23rd, 2006
0

Re: log in script saves cookie

Ok. I'll try to help, if you try to use apostrophes in your posts. Deal?

You set cookies using the "document.cookie" object. The arguments are name-value pairs:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.cookie =
  2. 'cookieName=cookieValue; expires=Thu, 23 Feb 2006 20:47:11 UTC; path=/'

Three pairs: the cookie name and value, the expiration date-time, and the path.

To read the cookie:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var x = readCookie('cookieName')
  2. if (x)
  3. {
  4. [do something with x]
  5. }

Try that, make sure you can at least write and read the cookie. You do know how to at least create an HTML document with scripts, right?
Last edited by tgreer; Feb 23rd, 2006 at 12:21 pm.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Problem in hovering
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Page Loading





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC