Making the cookie's name take the value of the username

They have: 16 posts

Joined: Mar 2001

I want to create a cookie for every user that logs in my site so that the next time a person attempts to log in, my code will search if a cookie exists for that user based on his username.

How do I write a cookie whose name will take the value of the username? Help!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

what language?

They have: 16 posts

Joined: Mar 2001

I want to know how to make the cookie's name take the value of the username using ASP and JavaScript.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

ASP (set cookie)

CookieValue = "logged in"
UserName = request.form("UserName")
Response.Cookies(UserName) = CookieValue
'
ASP (set session cookie)
CookieValue = "logged in"
UserName = request.form("UserName")
Session(UserName) = CookieValue
'
Javascript (set cookie)
// cookie expires after 1 month
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+1)

CookieValue = "logged in"
UserName = document.form_name.field_name.value
document.cookie = UserName + "=" + CookieValue + ";expires=" + expireDate.toGMTString()
'

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.