How to expire cookie when closing window

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/1829?pagenum=1
04 November 2025, 18:14

Topic


gent
How to expire cookie when closing window
05 November 2000, 17:51


I have the problem of the forum keeping the cookie alive when closing the window. I am automatically looged in when I start. I do not want this, since people will be logging on via public computers. Can I fix it?
/ Gent


/ Gent<

 

Replies ...


Davio
05 November 2000, 23:06


Well, 2 sure ways I can think of is, press the Logout button at the top before leaving the forum. You won't auto login the next time someone visits from the same computer.
Or you can manually delete the cookie from your computer that was created if you didn't logout of the forum.
*----*----*----*----*----*----*----*----*----*----*----*
"However, if you suffer as a Christian, do not be ashamed,
but praise God that you bear that name."
1 Peter 4:16
<
gent
06 November 2000, 00:54


Thanks, but this is not a very secure way. People will forget this from time to time. Is there not a way to limit the cookie's existence to the browser window? Also maybe a time-limit as well?
/ Gent

Edited by - gent on 06 November 2000 00:56:46<
jwilliams
10 November 2000, 18:04


jeeez... can't someone give these guys a good answer?
i am not an ASP developer (im really a Java dude), but I think you can use a global.asa file with a Session_OnStart method and use an ASP session instead of a cookie and then tell IIS to shorten the timeout of the session in your web server properties... errr whatever... this is actually pretty easy to do.
<
gor
10 November 2000, 18:11


Hey dude,

Could you please start reading your posts over once more before posting them ? The last few minutes I've been reading nothing but negative posts by you.
Because jeeeez... your answer wasn't that great either, because the easiest way to have a cookie expire when the browser closes is by just not setting the expiration date.
Please understand that all people posting here are trying to help other members. If you like to do that also, and are willing to do that in a polite way: please do so, we are happy with all the help we get smile If not, please stay away.
Pierre Gorissen
Even if you're on the right track,
you'll get run over if you just sit there.
Will Rogers<
Doug G
10 November 2000, 21:14


Relax, already smile
======
Doug G
======<
gent
11 November 2000, 03:27


Can you please tell me how to do this?
Kind Regards,

/ Gent

... because the easiest way to have a cookie expire when the browser closes is by just not setting the expiration date.


/ Gent<
gor
11 November 2000, 04:04


Ok, I'm not sure it fixes it for the forums all at once, but it should get you an idea of what to look for:

in inc_functions.asp you find this:

sub DoCookies()
if strSetCookieToForum = 1 then
Response.Cookies(strCookieURL & "User").Path = strCookieURL
else
Response.Cookies(strCookieURL & "User").Path = "/"
end if
Response.Cookies(strCookieURL & "User")("Name") = Request.Form("Name")
Response.Cookies(strCookieURL & "User")("Pword") = Request.Form("Password")
Response.Cookies(strCookieURL & "User")("Cookies") = Request.Form("Cookies")
Response.Cookies(strCookieURL & "User").Expires = dateAdd("d", 30, strForumTimeAdjust) Session(strCookieURL & "last_here_date") = ReadLastHereDate(Request.Form("Name"))
if strAuthType = "nt" then
Session(strCookieURL & "last_here_date") = ReadLastHereDate(Session(strCookieURL & "userID"))
end if
end sub

Now there are some more places in the code where cookies are set, if you want to find those just do a search for .Expires and you should be able to find them. I'm not sure what happens if there allready is a cookie there with .Expires set to something so you might need to have to delete your cookie(s) first.
If it works, please report back here because it would be nice to add this as a user-selectable option. (like you see at hotmail i.e.)

Pierre Gorissen
Even if you're on the right track,
you'll get run over if you just sit there.
Will Rogers<
Ken
11 November 2000, 12:09


I added ' in front of the .expire line and it works fine on my forums. How do I go about adding this as a feature for the user to select?
quote:
Ok, I'm not sure it fixes it for the forums all at once, but it should get you an idea of what to look for:

in inc_functions.asp you find this:

sub DoCookies()
if strSetCookieToForum = 1 then
Response.Cookies(strCookieURL & "User").Path = strCookieURL
else
Response.Cookies(strCookieURL & "User").Path = "/"
end if
Response.Cookies(strCookieURL & "User")("Name") = Request.Form("Name")
Response.Cookies(strCookieURL & "User")("Pword") = Request.Form("Password")
Response.Cookies(strCookieURL & "User")("Cookies") = Request.Form("Cookies")
Response.Cookies(strCookieURL & "User").Expires = dateAdd("d", 30, strForumTimeAdjust) Session(strCookieURL & "last_here_date") = ReadLastHereDate(Request.Form("Name"))
if strAuthType = "nt" then
Session(strCookieURL & "last_here_date") = ReadLastHereDate(Session(strCookieURL & "userID"))
end if
end sub

Now there are some more places in the code where cookies are set, if you want to find those just do a search for .Expires and you should be able to find them. I'm not sure what happens if there allready is a cookie there with .Expires set to something so you might need to have to delete your cookie(s) first.
If it works, please report back here because it would be nice to add this as a user-selectable option. (like you see at hotmail i.e.)

Pierre Gorissen
Even if you're on the right track,
you'll get run over if you just sit there.
Will Rogers

<
gor
11 November 2000, 12:44


Ehm, haven't thought about it very long yet, I think that the quickest way to do it is to add a checkbox in inc_top.asp so that it displays dissapprove Save password and then use this value to do something like

if checkbox = true then
Response.Cookies(strCookieURL & "User").Expires = dateAdd("d", 30, strForumTimeAdjust)
end if

so that the expires property only gets set if the checkbox is checked.


Pierre Gorissen
Even if you're on the right track,
you'll get run over if you just sit there.
Will Rogers<
Ken
11 November 2000, 14:36


Not sure if I did this correctly but I add this to the inc_top.asp and it does not save the cookie.
<input type="checkbox" name="savepassword" value="">
Save Password
<%
if checkbox = true then
Response.Cookies(strCookieURL & "User").Expires = dateAdd("d", 30, strForumTimeAdjust)
end if
%>

Any sugestions?
<
gor
11 November 2000, 15:26


Try this:

in inc_top.asp change this code starting around line 61:

select case Request.Form("Method_Type")

case "login"
select case ChkUser2(Request.Form("Name"), Request.Form("Password"))
case 1, 2, 3, 4
Call DoCookies(Request.Form("SavePassword")) strLoginStatus = 1
case else
strLoginStatus = 0
end select
case "logout"
Call ClearCookies()

end select

further down starting around line 193:

<%	if (strAuthType = "db") then %>
<td><font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>">Username:</font>
<INPUT type="text" name="Name" size="10" value=""></td>
<td><font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>">Password:</font>
<INPUT type="password" name="Password" size="10" value=""></td>
<td valign="bottom">
<% if strGfxButtons <> "0" then %>
<INPUT src=button_login.gif type="image" value="Login" id=submit1 name=submit1 border=0 hspace=4>
<% else %>
<% if strGfxButtons = "0" then %>
<INPUT type="submit" value="Login" id=submit1 name=submit1>
<% end if %>
<% end if %>
</td>
<tr>
<td colspan="3" align="left"><font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>">
<INPUT type="checkbox" name="SavePassWord" value="true"> Save my Password</font>
</td>
<% else %>

in inc_functions.asp change the DoCookies() function to:

sub DoCookies(fSavePassWord)
if strSetCookieToForum = 1 then
Response.Cookies(strCookieURL & "User").Path = strCookieURL
else
Response.Cookies(strCookieURL & "User").Path = "/"
end if
Response.Cookies(strCookieURL & "User")("Name") = Request.Form("Name")
Response.Cookies(strCookieURL & "User")("Pword") = Request.Form("Password")
Response.Cookies(strCookieURL & "User")("Cookies") = Request.Form("Cookies")
if fSavePassWord = "true" then
Response.Cookies(strCookieURL & "User").Expires = dateAdd("d", 30, strForumTimeAdjust)
end if
Session(strCookieURL & "last_here_date") = ReadLastHereDate(Request.Form("Name"))
if strAuthType = "nt" then
Session(strCookieURL & "last_here_date") = ReadLastHereDate(Session(strCookieURL & "userID"))
end if
end sub

in register.asp change line 268 to:

Call DoCookies("")
(this needs to be done or else you get an error when registering a new user)

Remember I didn't have time to check and re-check all the code, but the first few tests at my server worked: Only if you select the "save my password" checkbox before loggin on the username and password are saved after you close the browser.
Pierre Gorissen
Even if you're on the right track,
you'll get run over if you just sit there.
Will Rogers<
Huntress
21 November 2002, 08:07


You know this is done in an easier way by not allowing the save password function as follows, in inc_header.asp find this:

Code:

" <input type=""checkbox"" name=""SavePassWord"" value=""true"" tabindex=""-1"" CHECKED><b>Save Login </b>" & _

And change it to:

Code:

" <input type=""hidden"" name=""SavePassWord"" value=""false"" tabindex=""-1"">" & _

This removes the Save Password checkbox, and never saves the password to the cookie, thus they are not logged in when the browser is closed.
<
Gremlin
21 November 2002, 08:11


Did you notice the age of the thread ? hehe 2 years old was probably talking about version 3.1 or earlier back then.<
Huntress
21 November 2002, 09:09


LOL that's funny... I was researching something else and stubled across this and didn't notice the year... I thought it was only a few weeks old... jeez I'm embarrassed now. LOL

My new motto, I'm here to help, you just have to wait 2 years bigsmile<
Gremlin
21 November 2002, 09:20


ROFL :) Love the motto Huntress !<
davemaxwell
21 November 2002, 09:28


I officially nominate Huntress to be the "old bug" fixer! bigsmile<
Huntress
21 November 2002, 11:09


Thanks Dave I'm so honored! bigsmile
The one good thing about this is the lack of pressure LOL<
© 2000-2021 Snitz™ Communications