Liên kết tài nguyên

Liên kết website

Thành viên trực tuyến

5 khách và 0 thành viên

Thống kê

  • truy cập   (chi tiết)
    trong hôm nay
  • lượt xem
    trong hôm nay
  • thành viên
  • Điều tra ý kiến

    Bạn nhận thấy trang web này như thế nào?
    Rất hay
    Đẹp
    Bình thường
    Không hay
    Ý kiến khác

    Chào mừng quý thầy cô và các bạn đến với website Phan Tuấn Hải.

    Lên đầu trang Lên đầu trang
    Gốc > CHIA SẺ CODE TRANG TRÍ BLOG, WEB >

    Code đếm số lượng người đã truy cập

     
     
     

    Code:
    (global.asax)

    <script language="c#" runat=server>
    // sử lý sự kiện Session Start
    void Session_Start()
    {
        int count_visit = 0;

        //Kiểm tra file count_visit.txt nếu không tồn tại thì
        if(System.IO.File.Exists(Server.MapPath("count_visit.txt")) == false){
            count_visit = 1;
        }
        // Ngược lại thì
        else{
            // Đọc dử liều từ file count_visit.txt
            System.IO.StreamReader read = new System.IO.StreamReader(Server.MapPath("count_visit.txt"));
            count_visit = int.Parse(read.ReadLine());
            read.Close();

            // Tăng biến count_visit thêm 1
            count_visit ++;
        }

        // khóa website
        Application.Lock();
       
        // gán biến Application count_visit
        Application["count_visit"] = count_visit;
       
        // Mở khóa website
        Application.UnLock();
       
        // Lưu dử liệu vào file count_visit.txt
        System.IO.StreamWriter writer = new System.IO.StreamWriter(Server.MapPath("count_visit.txt"));
        writer.WriteLine(count_visit);
        writer.Close();
    }
    void Session_End(){

    }
    void Application_OnStart(){
       
    }
    void Application_OnEnd(){

    }
    </script>

    (main.aspx)

    <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <!–Hiển thị số người đả truy cập–>
    Đả có <strong><%=Application["count_visit"].ToString()%> </strong> người viến thăm
    </body>

    </html>


    Nhắn tin cho tác giả
    Phan Tuấn Hải @ 18:41 08/08/2009
    Số lượt xem: 924
    Số lượt thích: 0 người
     
    Gửi ý kiến