SoFunction
Updated on 2025-04-11

Three ways to accumulate visits on static pages

Static page
Copy the codeThe code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml" >
<head>
<title>Several ways to count dynamic page visits</title>
</head>
<body>
This is displayed in the layer
<div ></div>
<script src=""></script>
</body>
</html>

Accumulated page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="" Inherits="AddNumber" %>

Code
Copy the codeThe code is as follows:

public partial class AddNumber :
{
private static int count = 1;
protected void Page_Load(object sender, EventArgs e)
{
count++;
("var pv=('pv'); =" + count + ";");
}
}

The second method:
Static page
Copy the codeThe code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml" >
<head>
<title>Several ways to count dynamic page visits</title>
</head>
<body>
This is to use pictures to display
<img src="" alt="This is the number of dynamic statistics" />
</body>
</html>

Accumulated page
Copy the codeThe code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="" Inherits="ImageAddNumber" %>


Code
Copy the codeThe code is as follows:

public partial class ImageAddNumber :
{
private static int count = 1;
protected void Page_Load(object sender, EventArgs e)
{
count++;
string pv = ();
image = new ((int)(( * 12.5)), 22);
Graphics g = (image);
//Picture background color
();
Font font = new ("Arial", 12, ( | ));
. brush = new .(new Rectangle(0, 0, , ), , , (float)1.2f, true);
(pv,font, brush, 0, 0);
(new Pen(), 0, 0, - 1, - 1);
ms = new ();
(ms, );
();
= "image/Gif";
(());
}
}

The third method:
Static page
Copy the codeThe code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml" >
<head>
<title>Several ways to count dynamic page visits</title>
</head>
<body>
This is implemented using Ajax
<div ></div>
<script language="javascript" type="text/javascript">
function addPv(){
//Create a cross-browser XMLHttpRequest object
var xmlhttp;
try{
xmlhttp= new ActiveXObject('');
}catch(e){
try{
xmlhttp= new ActiveXObject('');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
//Create a request
("get","?news=1");
=function(){
if(==4){
if(==200){
//Judge whether the user name exists based on responseText
var repv=;
var mypv=("ajaxpv");
=repv;
/*alert(repv);*/
}else{
alert("Network failed.");
}
}
} ;
(null);
("addPv",1000);
}
=addPv;
</script>
</body>
</html>

Accumulated page
Copy the codeThe code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="" Inherits="AjaxPv" %>


Copy the codeThe code is as follows:

public partial class AjaxPv :
{
private static int count=1;
protected void Page_Load(object sender, EventArgs e)
{
//Accumulate to the database
//Read data from the database, currently
count = 5;
(count);
}
}