User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 360,995 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,423 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2372 | Replies: 5
Reply
Join Date: Feb 2006
Posts: 4
Reputation: Aperson is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Aperson Aperson is offline Offline
Newbie Poster

log in script saves cookie

  #1  
Feb 21st, 2006
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: log in script saves cookie

  #2  
Feb 21st, 2006
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.
Reply With Quote  
Join Date: Feb 2006
Posts: 4
Reputation: Aperson is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Aperson Aperson is offline Offline
Newbie Poster

Re: log in script saves cookie

  #3  
Feb 22nd, 2006
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?
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: log in script saves cookie

  #4  
Feb 22nd, 2006
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.
Reply With Quote  
Join Date: Feb 2006
Posts: 4
Reputation: Aperson is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Aperson Aperson is offline Offline
Newbie Poster

Re: log in script saves cookie

  #5  
Feb 22nd, 2006
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. ?
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: log in script saves cookie

  #6  
Feb 23rd, 2006
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:

document.cookie =
  '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:

var x = readCookie('cookieName')
if (x)
{
	[do something with x]
}

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 11:21 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC