XML + application to compile counters (1)

Source: Internet
Author: User
1) Total Website Visitors counter

We can use XML to implement this type of counter. Open the windows notepad and enter the following data as count. xml.

<Mycount>

<Allcount> 0 </allcount>

<Maxcount> 0 </maxcount>

</Mycount>

The allcount tag records the total number of web page visits.CodeManipulate this XML file

<% @ Import namespace = "system. Data" %>

<% @ Import namespace = "system. Data. oledb" %> // import...

<Script language = "C #" runat = Server>

Httpcookie ckecount = new httpcookie ("count"); // a cookie variable used to determine whether a visitor is on your website

Void page_load ()

{

If (request. Cookies ["count"] = NULL) // If the cookie is empty, it indicates that your page is loaded for the first time.

{

Ckecount. value = "true"; // Add a value to the cookie

/* Here is an optional code to check whether the cookie is invalid. If you set it to one month, a visitor has visited your site before, and his cookies contain the value you saved, in addition, if the cookie is not cleared, the visitor will not add 1 to the counter when loading the page. If you do not set the cookie retention time, then, when a visitor leaves your site, the cookie disappears automatically.

Datetime dt = datetime. now;

Timespan Ts = new timespan (30, 0, 0, 0 );

Ckecount. expires = DT + ts;

*/

************************* * ** 8

Dataset objdataset = new dataset ();

Objdataset. readxml (server. mappath ("count. xml"); // dataset reads XML files

Objdataset. tables ["mycount"]. rows [0] ["allcount"] = convert. toint64 (objdataset. tables ["mycount"]. rows [0] ["allcount"]) + 1; // write here, for example, XML, to update the value of the first allcount tag + 1

Objdataset. writexml (server. mappath ("database/count. xml"); // write data such as XML

Response. Cookies. Add (ckecount); // write cookies

}

Lbcount. Text = "Total" + objdataset. Tables ["mycount"]. Rows [0] ["allcount"]. tostring (); // displayed on the page

}

</SCRIPT>

<Asp: Label runat = server id = lbcount/>

Write counters using XML + application (2)

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.