CuDemVN.Wap.Sh



![]() | ![]() ![]() ![]() |
Code tạo bộ đếm lượt truy cập đơn giản cho code viết bằng php. Code sẽ hiển thị bộ đếm trong ngày và bộ đếm tổng cộng khá chuẩn
Hướng dẫn cài đặt code đếm lượt truy cập
- Bước 1: Tạo 1 file mới với tên count.php mở file count.php dán đoạn mã này vào:
<?php
$counter = "./counter.txt";
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$current_date = $mday.$month.$year;
// Log visit;
$fp = fopen($counter, "a");
$line = $REMOTE_ADDR."|".$mday.$month.$year."\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);
$contents = file($counter);
$total_hits = sizeof($contents);
$total_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
array_push($total_hosts, $entry[0]);
}
$total_hosts_size = sizeof(array_unique($total_hosts));
$daily_hits = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hits, $entry[0]);
}
}
$daily_hits_size = sizeof($daily_hits);
$daily_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hosts, $entry[0]);
}
}
$daily_hosts_size = sizeof(array_unique($daily_hosts));
?>
- Bước 2: Mở file cần chèn bộ đếm tìm đoạn
<?php
Chèn vào dưới:
include("count.php");
- Bước 3: Tìm tới nơi cần đặt bộ đếm thêm code này vào
echo "Today: ".$daily_hits_size." | Total: ".$total_hits."";
Như vậy chỉ với vài bước đơn giản như trên bạn đã tạo bộ đếm truy cập cho Wap mình rồi đấy. Các bạn có thể copy code phía trên hoặc tải file mình đã zip code sẵn


Chúc các bạn thành công!
Nguồn: TuoiTreIT
↓ Tập tin Đính kèm ↓

Đánh giá: 4.5/ 5, 2082 bình chọn
