Results 1 to 4 of 4

Thread: how can i check for cookies

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    66

    how can i check for cookies

    I have a need for a simple cookie. When a user clicks a link to vote I want the code to check for a cookie. if the value of the cookie is true, do not let the person vote (1 vote per person). Else allow the person to vote and place a cookie on their box.

    My code doesn't seem to be working. Any thoughts?
    VB Code:
    1. If IsDBNull(Request.Cookies("PplsChoice")) Then
    2.             Dim Cookie As New HttpCookie("PplsChoice")
    3.             Dim Item As String = Request.QueryString("i")
    4.             Dim cmd As New ExecuteCommand(AppSettings("cnn") & Server.MapPath("\GalleryCatalog\DataSource\TEST_auction_data.mdb"))
    5.  
    6.             'update catalog table
    7.             If cmd.SetData("UPDATE Catalog_tbl SET PplsChoiceTally = [pplschoicetally] + 1 WHERE ItemNumber = '" & Item & "'") Then
    8.                 'append cookie to flag the computer's vote
    9.                 Cookie.Expires = #4/16/2004#
    10.                 Cookie.Values.Add("Voted", "True")
    11.                 Response.Cookies.Add(Cookie)
    12.                 lblVote.Text = "Thank you for casting your vote for People's Choice the results will be determined on " & AppSettings("Date.PplsChoice")
    13.                 lblVote.ForeColor = Green
    14.             Else
    15.                 lblVote.Text = "We're sorry, your vote was not tallied, please try again. If the problem continues contact WITF to cast your vote."
    16.                 lblVote.ForeColor = Red
    17.             End If
    18.         Else
    19.             lblVote.Text = "We're sorry, our records show you have already casted a vote for People's Choice."
    20.             lblVote.ForeColor = Red
    21.         End If
    22.         lblVote.Visible = True
    Jason Meckley
    Database Analyst
    WITF

  2. #2
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    Try this instead

    VB Code:
    1. If len(Request.Cookies("PplsChoice")) <1 then
    2. ' Noo cookie
    3. end if

    I'm pretty sure its the isDBNull method that is not working. You can use isNothing() instead of len call


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    66
    this works if there is no cookie, but once there is a cookie I get a type mismatch error.
    Jason Meckley
    Database Analyst
    WITF

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    66
    I found code that wouldn't error out.
    VB Code:
    1. If request.cookie("PplsChoice") is Nothing then
    Jason Meckley
    Database Analyst
    WITF

Posting Permissions

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



Click Here to Expand Forum to Full Width