Quantcast
Channel: Recent posts across whole site
Viewing all articles
Browse latest Browse all 49197

Tạo block đếm số người đã truy cập

$
0
0

Mục đích: Tạo một block với nội dung là số lượng người đã truy cập vào website.
Các thực hiện:
1. Đăng nhập với user có quyền tạo block mới và sử dụng PHP code filter
2. Vào trang điều hành block, click vào tab tạo block mới
3. Cấu hình block tùy thích, phần block body tương tự như mục 4:
4.

<?php
 
print $pagehit = variable_get('site_pagehit',0);
  if(
db_num_rows( db_query("SELECT sid FROM {sessions} WHERE sid = '%s'",session_id()) ) == 0 ){
   
variable_set('site_pagehit',$pagehit+1);
  }
?>

Giải thích:
- Dòng 1: Đi lấy biến site_pagehit, nếu chưa có thì gán giá trị là 0. Xuất giá trị lấy được
- Dòng 2: Nếu như người truy cập mới bắt đầu session
- Dòng 3: Tăng giá trị site_pagehit lên 1.

AttachmentSize
whosonline.JPG6.2 KB

Viewing all articles
Browse latest Browse all 49197

Trending Articles