SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP - How to Check for Cookies Enabled?

    I need to determine if my users have cookies enabled. My solution is to write a script that will create a cookie, redirect to another page, check for the cookie, and if the cookie is there ... voila! ... cookies are in fact enabled. What do you guys think of this and how do y'all determine if your users have cookies enabled?

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    We just ran up against a similar thing, and my colleague just suggested the same thing...

    I'm sure there is a better way, though I don't know...
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Enthusiast stephan_100's Avatar
    Join Date
    Nov 2001
    Location
    Toronto, Ontario, Canada
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont really know how to do this because I'm new with ASP, but this is the only way that I could think of doing it. You could create an if statement, and if it comes out false then their cookies are diabled.


    <%

    if request.cookies("cookie_name") = false Then

    'this is where the user goes if their cookies are off
    response.redirect("something.com")

    end if

    %>


    Like I said before, I'm not sure how to do this, but this is my best guess. If anyone knows for sure how to do this, please post it here, because I will need to know how to do this later on for my site.

    Thanks
    Stephan M.
    Computer Forums -- Supplies All The Help You Need
    http://www27.brinkster.com/cforums

  4. #4
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That would detect the presence of an individual cookie (if isNull(request.cookies("cookiename")) would be better).

    We need some way of detecting if a user's cookies are enabled. Client-side may be the only way to do this though
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't it be simple?

    Code:
    <% Response.Cookies("testing") = "Yo"
       If Request.Cookies("test") != "Yo" Then
         Response.Write "Cookies not enabled"
       Else 
         Response.Cookies("realcooke") = "SomeData"
       End If %>
    Wouldn't that work? (sorry, haven't used ASP in awhile...my code might not actually work without some tweaking).
    Last edited by TWTCommish; Nov 13, 2001 at 11:02.

  6. #6
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You'll actually get an error when you try and read the cookie (object expected).
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  7. #7
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pshaw...there's got to be a simple server-side way to check. I'll see if I can find something.

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about converting the cookie to a boolean value first using some sort of typecasting? Think that would work? I was also thinking you could try something like this:

    Code:
    If Response.Cookies("test") = "Yo" then
    I dunno if ASP can handle a conditional in the form of a statement that assigns a value, though...PHP can (now I remember why I dislike ASP ). Oh, I also corrected a typo I had above: I changed "Response" to "Request" in the conditional...I dunno if that'll help or not, though (it might...I can't check from this computer, unfortunately).
    Last edited by TWTCommish; Nov 13, 2001 at 11:02.

  9. #9
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,263
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by TWTCommish
    Response.Cookies("testing") = "Yo"
    If Request.Cookies("test") != "Yo" Then
    [/code]
    It would help if you check the same thing that your write out
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  10. #10
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stupid typos...that's two in just one block of code. D'oh!

  11. #11
    SitePoint Wizard iTec's Avatar
    Join Date
    May 2001
    Location
    Sydney, Australia
    Posts
    2,243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    writhe answered his own question,
    take a look at http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=29


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •