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)