Print Page | Close Window

Problem with cookies

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=13119
Printed Date: 30 March 2026 at 6:20pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Problem with cookies
Posted By: photoshop_god
Subject: Problem with cookies
Date Posted: 26 December 2004 at 7:28pm
Hi all,
 
I have been looking and playing around with this code trying to figure out why I get this error.
 
Here is the code that is causing the problem:
 
'Set the destination URL
''********************************************************** **************
DestURL = rs("DestURL")
 
Response.Cookies(strCookieName)("GPAUsername") = rs("GPAUsername")
Response.Cookies(strCookieName)("FirstName") = rs("FirstName")
Response.Cookies(strCookieName)("LastName") = rs("LastName")
Response.Cookies(strCookieName)("Email") = rs("Email")
Response.Cookies(strCookieName)("Account1") = rs("Account1")
Response.Cookies(strCookieName)("Account2") = rs("Account2")
Response.Cookies(strCookieName)("Account3") = rs("Account3")
Response.Cookies(strCookieName)("UserGood") = "Yes"
Response.Cookies(strCookieName)("Admin") = rs("Admin")
Response.Cookies(strCookieName)("Location") = rs("Location")
Response.Cookies(strCookieName)("Valid") = rs("Valid")
Response.Cookies(strCookieName)("Suspended") = rs("Suspended")
Response.Cookies(strCookieName).Domain = " http://www.gpagallery.com - www.gpagallery.com "
Response.Cookies(strCookieName).Expires = strExpireDate
Session("UserMessages") = rs("UserMessages")
 
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Response.Redirect DestURL
Else

'Set the destination URL
''********************************************************** **************
DestURL = rs("DestURL")
 
Session("GPAUsername") = rs("GPAUsername")
Session("FirstName") = rs("FirstName")
Session("LastName") = rs("LastName")
Session("Email") = rs("Email")
Session("Account1") = rs("Account1")
Session("Account2") = rs("Account2")
Session("Account3") = rs("Account3")
Session("UserGood") = "Yes"
Session("Admin") = rs("Admin")
Session("Location") = rs("Location")
Session("UserMessages") = rs("UserMessages")
Session("Valid") = rs("Valid")
Session("AutoLoginReminder") = "Yes"
Session("Suspended") = rs("Suspended")
 
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Response.Redirect DestURL
 
The code works fine when you use the session variables but when you use the cookies I get this error
 
Microsoft VBScript runtime error '800a000d'

Type mismatch: '[object]'

/login_checkuser.asp, line 163

line 163 is Response.Cookies(strCookieName)("Account1") = rs("Account1")
The Account1 field is setup just like the first name field.(a text field)  I'm using an access 2000 database running on a win 2000 server.
This error happens when I leave this field blank.  When I populate it I get the error on the Account2 line.  I tried leaving another field blank like location or first name and I have no problems.  I'm scratching my head trying to figure out what is going on.  Any help would be appreciated. 



Replies:
Posted By: dpyers
Date Posted: 26 December 2004 at 11:13pm
Cookies tend to be sensitive to null values. More than likely the Account fields in your db default to null when empty. Try something like
Response.Cookies(strCookieName)("Account1") = "" & rs("Account1")
which has the effect of concatenating an empty string with the db field.
 
Another way to do it is
If IsNull(rs("Account1")) then
    Response.Cookies(strCookieName)("Account1") = ""
else
    Response.Cookies(strCookieName)("Account1") = rs("Account1")
End If
 
A null string is not the same as an empty string. A string has hidden end-of-string characters that cookies like. Some browsers and some server settings regard a null in a cookie as a cookie block.
 
EDIT: To add color highlight


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: photoshop_god
Date Posted: 27 December 2004 at 9:06am
Thanks dpyers
 
I guess I didn't realize that about cookies.  I'll give this a try.  I'm sure this is what the problem is.  Thanks again.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net