Asp statistics implementation code/Article daily, weekly, monthly, and total visits

Source: Internet
Author: User

Copy codeThe Code is as follows: <%
'// Hittime date type: Get the last access time
'// Hits numeric type: obtains the total page views.
'// Hitsday numeric type: get today's page views
'// Hitsweeks numeric type: Get the page views of this week
'// Hitmonths numeric type: Get the page views this month
'Add these five fields to the database.
Set rs1 = server. CreateObject ("adodb. recordset ")
Rs1.open "select * from qwbmnewssss where id = 26", conn, 1, 3
If rs1.eof and rs1.bof then
Response. write "erry"
Else
Hittime = rs1 ("hittime") 'gets the last access time
Dim dayNow, monthNow, weeknow
DayNow = day (date () 'current number
MonthNow = month (date () 'current month
WeekNow = weekday (date () 'today, the day of the week 0 is Sunday
Rs1 ("hits") = rs1 ("hits") + 1' total browsing times + 1

If datediff ("d", hittime, now () = 0 then' compare the last access date with the current time day
Rs1 ("hitsday") = rs1 ("hitsday") + 1' today's views + 1
Else
Rs1 ("hitsday") = 1' today's views = 1
End if

If monthNow = month (hittime) then
Rs1 ("hitmonths") = rs1 ("hitmonths") + 1' views this month + 1
Else
Rs1 ("hitmonths") = 1' views this month + 1
End if

If datediff ("d", hittime, now ()> 6 then' has a problem during the week. if the last time is Friday, the next access is the Tuesday of the next week, record or overlay.
Rs1 ("hitsweeks") = 1
Else
If weekNow <> 1 then
Rs1 ("hitsweeks") = rs1 ("hitsweeks") + 1
Else
WeekNowss = weekday (hittime) 'last visit day of the week
If weekNow = weekNowss then
Rs1 ("hitsweeks") = rs1 ("hitsweeks") + 1
Else
Rs1 ("hitsweeks") = 1
End if
End if
End if

Rs1 ("hittime") = now () 'update the last access question
Rs1.update
%>
Time Comparison: <% = datediff ("d", hittime, now () %> <br/>
Current Time: <% = now () %> <br/>
Last Click Time: <% = hittime %> <br/>
Current day: <% = dayNow %> <br/>
Current month: <% = monthNow %> <br/>
Current week: <% = weekNow %> <br/>

Total page views: <% = rs1 ("hits") %> <br/>
Traffic Volume today: <% = rs1 ("hitsday") %> <br/>
Weekly Traffic: <% = rs1 ("hitsweeks") %> <br/>
Traffic Volume for the current month: <% = rs1 ("hitmonths") %> <br/>
<%
End if
Rs1.close
Set rs1 = nothing
%>

Related Article

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.