Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: date cookie

  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    95
    Thanks
    13
    Thanked 1 Time in 1 Post

    date cookie

    Hello according to this i found:


    Code:
    <%
    dim numvisits
    response.cookies("NumVisits").Expires=date+365 
    numvisits=request.cookies("NumVisits")
    
    if numvisits="" then
       response.cookies("NumVisits")=1
       response.write("Welcome! This is the first time you are visiting this Web page.")
    else
       response.cookies("NumVisits")=numvisits+1
       response.write("You have visited this ")
       response.write("Web page " & numvisits)
       if numvisits=1 then
         response.write " time before!"
       else
         response.write " times before!"
       end if
    end if
    %>



    which result:
    "You have visited this Web page 2 times before!" ......ets


    I wonder if there is a way to display the days since last visit, for example:
    "You have visited this Web page 15 days before!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,857
    Thanks
    78
    Thanked 4,417 Times in 4,382 Posts
    Let's write that code in a more logical way.

    And stop using ( ) around the argument to response.write. It works, but it's technically wrong and a tiny performance hit.

    Code:
    <%
    dim numvisits
    numvisits=request.cookies("NumVisits")
    if numvisits="" then
       numvisits = 0
       response.write "Welcome! This is the first time you are visiting this Web page.<br/>"
    else
       if numvisits > 1 then v = " times " else v = " time "
       response.write "You have visited this Web page " & numvisits & v & " before.<br/>"
       response.write "Last visit was " & request.cookies("LastVisit") & "<br/>"
    end if
    ' update cookies:
    response.cookies("NumVisits")=numvisits+1
    response.cookies("LastVisit") = Now()
    response.cookies("NumVisits").Expires=date()+365 
    response.cookies("LastVisit").Expires=date()+365 
    %>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    garevn (11-03-2011)

  • #3
    New Coder
    Join Date
    Apr 2011
    Posts
    95
    Thanks
    13
    Thanked 1 Time in 1 Post
    Thanks man u saved my day.
    Also i tryed and using the DateDiff function i managed to display also the days between the 2 dates,


  •  

    Posting Permissions

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