📄 counter.aspx
字号:
<%@ Page Language="JScript"%>
<%@ Import Namespace="System.IO" %>
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>
<%@ Import namespace="System.Drawing.Drawing2D" %>
<%
if(Request.QueryString("item")=="")
return;
var itm :String = Request.QueryString("item");
var cookie:HttpCookie;
cookie = Request.Cookies("LastVisit");
//var readOnly:Boolean = (cookie!=null);
//将以下语句换成上面的语句即可防止刷新;
var readOnly:Boolean=false;
drawCounter(itm,readOnly);
if(!readOnly) {
cookie = new HttpCookie("LastVisit",DateTime.Now.AddSeconds(10));
cookie.Expires = DateTime.Now.AddSeconds(60);
Response.AppendCookie(cookie);
}
function createCounter(nameOfItem:String)
{
var sw : StreamWriter;
var filePath:String = Server.MapPath("data\\") + nameOfItem + ".txt";
if(!File.Exists(filePath)) {
sw=File.CreateText(filePath);
sw.WriteLine("0");
sw.Close();
}
}
function getCounterValue(nameOfItem:String,readOnly:Boolean) : String
{
var fileIn:StreamReader = File.OpenText(Server.MapPath("data\\" + nameOfItem + ".txt"),FileMode.Open);
var current : String = new String("");
current = fileIn.ReadLine().ToString();
fileIn.Close();
if(readOnly)
return current;
var curInt : int = Convert.ToInt32(current);
curInt++;
var fs: FileStream = new FileStream(Server.MapPath("data\\" + nameOfItem + ".txt"), FileMode.Open,FileAccess.Write);
var sw : StreamWriter;
sw = new StreamWriter(fs);
sw.WriteLine(Convert.ToString(curInt));
sw.Close();
fs.Close();
return Convert.ToString(curInt);
}
function drawCounter(nameOfItem:String,readOnly:Boolean)
{
createCounter(nameOfItem);
var counterValue : String = getCounterValue(nameOfItem,readOnly);
var height:int=20;
var width:int=150;
var bmp : Bitmap= new Bitmap(width, height);
var g:Graphics = Graphics.FromImage(bmp);
// Create a DarkBlue background
g.FillRectangle(new SolidBrush(Color.Blue), 0, 0, width, height);
// LightGreen for the small box on the left...
g.FillRectangle(new SolidBrush(Color.LightGreen), 0, 0, 55, 20);
var maroonBrush:SolidBrush= new SolidBrush(Color.Maroon);
var blackBrush:SolidBrush= new SolidBrush(Color.Black);
var counterByFont:Font = new Font("宋体", 9, FontStyle.Bold);
g.DrawString("访问人数", counterByFont,blackBrush ,0,5);
//g.DrawString("华", counterByFont,maroonBrush ,12,5);
//g.DrawString("网", counterByFont,blackBrush ,24,5);
var counterFont:Font = new Font("Verdana", 8, FontStyle.Bold);
var whiteBrush:SolidBrush= new SolidBrush(Color.White);
var counterText : SizeF;
counterText = g.MeasureString(counterValue,counterFont);
g.DrawString(counterValue, counterFont, whiteBrush ,(bmp.Width)-((counterText.Width)+5),3);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -