A perfect counter (how to prevent users from refreshing the page plus 1)

Source: Internet
Author: User
Counter | refresh | page Hello everyone!
Today I want to talk about a Web page counter problem, some Web site counters in the User Refresh page, the value will be added 1, such counters are not sound. If your site is doing some award-winning activities, for example, "If you are the 100,000th user you will get the prizes provided by this site".
So, here's the original code for a counter, and you're going to create a new Counter.txt file under this ASP file that holds the value.
<%
function counts (counterfile)

Dim Objfso,objts
Application.Lock ' Lock Object
Set Objfso=server.createobject ("Scripting.FileSystemObject")
Set Objts=objfso.opentextfile (Server.MapPath (counterfile), 1,true)
If not Objts.atendofstream then ' check to reach end of file
COUNTS=CLNG (Objts.readline)
End If
Counts=counts+1
Objts.close
Set Objts=objfso.opentextfile (Server.MapPath (counterfile), 2,true)
objTS.WriteLine (counts)
Objts.close
Application.UnLock ' unlock
End Function

If session ("Counter") =empty Then
Session ("Counter") =counts ("Counter.txt")
End If
%>

<body>
You are <%=session ("counter")%> Guest
</body>
Such a perfect counter is made.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.