Results 1 to 3 of 3

Thread: asp if cookie

  1. #1
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default asp if cookie

    Hi, would anyone know how to write a cookie based if clause to this.
    I need a cookie to remember a user and if they click a link more than once it is not recorded.
    this is the code bit that adds the record, I need it to say if peson has followed that link before dont add 1 to the database.



    Code:
    	
    
    	' If it's EOF then it's the first hit of the day and we need
    	' to add a new record o/w we simply update the existing hit
    	' count of the record by adding one to it.
    If rsLinkTracker.EOF Then
    		rsLinkTracker.AddNew
    		
    		rsLinkTracker.Fields("link_id").Value   = iRedirectId
    		rsLinkTracker.Fields("hit_date").Value  = Date()
    		rsLinkTracker.Fields("hit_count").Value = 1
    	Else
    		rsLinkTracker.Fields("hit_count").Value = _
    			rsLinkTracker.Fields("hit_count").Value + 1
    	End If

    Any pointers as to how to write it and a cookie would be a great help
    thanks richard

  2. #2
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Try with Session Cookies...

    If you add a Session Cookie after the INSERT, then the user could not click the link again... something like this:

    Code:
    If rsLinkTracker.EOF Then
      If Session ("hit_count") = "" then
        rsLinkTracker.AddNew
        rsLinkTracker.Fields("link_id").Value   = iRedirectId
        rsLinkTracker.Fields("hit_date").Value  = Date()
        rsLinkTracker.Fields("hit_count").Value = 1
        Session("hit_count") = "Y"
      End If
    Else
      If Session ("hit_count") = "" then
        rsLinkTracker.Fields("hit_count").Value = _
        rsLinkTracker.Fields("hit_count").Value + 1
      End If
    End If
    So If the user never clicked the link, and the hit count of that day is null, then the INSERT occurrs and the session cookie is saved. The session cookie timeout is 90 minutes, but you can change it from IIS or the Session Timeout property. The only way the user can "cheat" the code is waiting 90 minutes or closing every browser window each time he wants to record a hit. If you really mind someone would do that, then you can change stop him by saving a Cookie (not a Session one) and setting the Expires option to a date in the future, like 1 year from now. The only way the user can cheat it is by deleting the cookies every time he wants to cheat the counter. You can stop him by saving the IP of the last record together with the session cookies and the cookies.

  3. #3
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Red face Fix to previous post...

    I forgot to save the Session Cookie after the UPDATE, sorry about that, here's the fixed code:

    Code:
    If rsLinkTracker.EOF Then
      If Session ("hit_count") = "" then
        rsLinkTracker.AddNew
        rsLinkTracker.Fields("link_id").Value   = iRedirectId
        rsLinkTracker.Fields("hit_date").Value  = Date()
        rsLinkTracker.Fields("hit_count").Value = 1
        Session("hit_count") = "Y"
      End If
    Else
      If Session ("hit_count") = "" then
        rsLinkTracker.Fields("hit_count").Value = _
        rsLinkTracker.Fields("hit_count").Value + 1
        Session("hit_count") = "Y"
      End If
    End If

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
  •