Verify cookies

Discussion in 'ASP General' started by Zap, Jul 10, 2003.

  1. Zap

    Zap Guest

    I'm having trouble verifying the cookie that I leave on a client's computer.
    Here is the code:

    <%
    Dim sPath, filesys, count, getValue, update, twohrs

    sPath = Request.ServerVariables("Path_Translated")
    sPath = Left(sPath,InStrRev(sPath,"\")) & "counter.txt"

    Set filesys = CreateObject("Scripting.FileSystemObject")

    Set getValue = filesys.OpenTextFile(sPath,1,0)
    ' get the current value
    count = getValue.ReadLine
    If Request.Cookies("hpd")("user") <> "rvisitor" or
    Request.Cookies("hpd")("user") <> "admin" Then
    ' increment by 1 before displaying, 'cos they're a newbie
    count = Int(count) + 1
    getValue.Close

    ' overwrite old text file with new one
    Set update = filesys.CreateTextFile(sPath)

    ' put new value in text file
    update.WriteLine(count)
    update.Close

    ' give them a cookie to make sure it doesn't count them more than once
    Response.Cookies("hpd")("user") = "rvisitor"
    ' make it expire in 2 hours' time
    twohrs = DateAdd("h", 2, Now)
    Response.Cookies("hpd").Expires = twohrs

    End If

    %>
    I want admin to be on a few computers that do updates to the webpage. That
    way they aren't counted every vist. The problem is that it always
    overwrites the cookie with a rvisitor even if admin is present. It will
    also count rvisitor twice within two hours if the person hits the homepage
    twice while their cookie hasn't expired.

    TIA,
    Zap
     
    Zap, Jul 10, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,579
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,582
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    687
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    526
  5. _Who
    Replies:
    7
    Views:
    2,751
Loading...

Share This Page