creating a login cookie

He has: 688 posts

Joined: Feb 2001

(Sorry if this topic was covered somewhere earlier)

A friend of mine has a site that has lots of "members only pages". What's annoying is that everytime you visit you need to login again with your email address and password. I told him that he should use a cookie (and a checkbox) to 'remember' the user to automatically login in again everytime an authorized visitor returns. He said he doesn't know anyting about cookies and since I'm the one who suggested it, now I'm trying to figure out how to do this on his behalf.

Things to know:
1) I have no idea what langueage he wrote his site in but if that's essential I can find out.
2) It's nothing so important where a simple "remember me" cookie poses any real security issue. It's just a simple alumni message board.

He has: 1,016 posts

Joined: May 2002

I suggest you find out what language the members area is written in. I mean, if it's in ASP, it wouldn't help if you provided you with PHP code..

He has: 688 posts

Joined: Feb 2001

Quote: Originally posted by zollet
I suggest you find out what language the members area is written in. I mean, if it's in ASP, it wouldn't help if you provided you with PHP code..

His answer was "The site is all in ASP which mixes VBScript, JavaScript, and HTML."

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

And so, I'm moving this to the Scripting Forum... Wink

ASP Login is the question.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

<%

' creating/updating a cookie
Response.Cookies("Username") = Username
Response.Cookies("Username").Expires = DateAdd("d", 1, Date)
Response.Cookies("Password") = Password
Response.Cookies("Password").Expires = DateAdd("d", 1, Date)

' reading a cookie
Username = Request.Cookies("Username")
Password = Request.Cookies("Password")

' clearing a cookie
Response.Cookies("Username") = ""
Response.Cookies("Password") = ""

%>
'You'll need to check/read the cookie, then jump to wherever the script starts the session. Basically faking a form submission. Hopefully, the session creation was put in a function or subroutine that you can easily call.

You'll probably want to create a header file you can include everywhere. That way, no matter where they enter the site, it will read the cookie and log them in.

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

He has: 688 posts

Joined: Feb 2001

Thanks. I passed this along. If he has more questions I'm going to suggest that he come here to ask directly. Thanks again.

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.