• Post Reply Bookmark Topic Watch Topic
  • New Topic

cookies are disable/session  RSS feed

 
marg wright
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be a good way to test if cookies/and therefore their session would be disable, and have a message display to enable their cookies?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set a cookie and try to read it back. If you can't, they must have cookies turned off.

If you just want to ensure cookies are enabled for the purpose of session tracking, then you can ensure that any and all URLs that are 'emitted' by your application are first run through the encodeURL method of the HttpServletResponse object. That way, it won't matter if they have cookies enabled or not.
[ July 23, 2002: Message edited by: Mike Curwen ]
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marg
Had some trouble getting this to post, it looks like it doesn't like the word cookie in the code below so I to put a space in the word...
Like Mike said the easiest way to do it, and avoid a round trip to the server, would be to use java script. All you need to do is set a cookie and then retrieve it and test to see if it has the same value as it was set with.
Here is some code to do that:

If your using cookies for session tracking keep in mind you can also use url rewriting. I say this because some people dont trust cookies and may not enbale them and might not come back to your site becasue of them.
[ July 23, 2002: Message edited by: Dave Vick ]
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If javascript is disabled, then as Mike said, you can add a cookie to the response to the client, then see if you can read it back.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!