09/10/2018, 18:08

[Q] Đếm số người đang truy cập trang web

Tôi đang thiết kế một website dùng php, Mysql, Tôi muốn biết số người đang truy cập vào trang web của tôi , ai biết chỉ giúp , Cám ơn trước nhé.
Saigon75 viết 20:10 ngày 09/10/2018
Bạn dùng thử cái này xem sao !

<!----------- save this file as count.php ------------>
<?php
/* +------------------------------------------------------------+
Page Counter v1.5.0 Filename: count.php
Copyright 1998-2001 Telematics Software
All Rights Reserved
Author: mr.shifter@hosted.uklinux.net
http://www.hosted.uklinux.net/php/freescripts/index.php

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed WITHOUT ANY WARRANTY of
MERCHANTABILITY or FITNESS FOR ANY PARTICULAR PURPOSE.
Your usage of this programme is entirely at your own risk

Make a text file called 'count.txt' place it in the same
directory as this php script. On unix you will need to
chmod 'count.txt' to 666 for read/ write permissions
Make another directory call it 'images' and place in here
your graphical image files numbered from 0.gif to 9.gif
+-----------------------------------------------------------+ */
/* Set Necessary Variables: */

$counterfile= "./count.txt"; #absolute path/directory as required
$imagedir= "./images"; # absolute path/directory as required No trailing slash
$type=1; # 1=graphic display, 0= text display
$ext=".gif"; # use .gif, .jpeg or .png as needed

/* End Variables section */

if(! ($fp = fopen($counterfile, "r"))) die ("Can not open $counterfile.");
$counter = (int) fread($fp, 20);
fclose($fp);

$counter++;
$image_tag_str = ""; // Leave empty
for ($i=0; $i < strlen($counter); $i++)
{
$image_src = $imagedir."/".substr($counter, $i, 1) .$ext;
$image_tag_str .="<IMG SRC=\"$image_src\" BORDER=\"0\">";
}

// then display the graphic or text image
// to use a hidden counter comment out the next five lines
if($type==1){
echo("You Are Visitor No: $image_tag_str" );
}else{
echo("You Are Visitor No: $counter" );
}

if(!($fp= fopen($counterfile, "w"))) die ("Can not write to $counterfile");
fwrite($fp, $counter);
fclose($fp);

?>
<!---------- end of count.php ------------------------------>

<!---------- Save next file as count.txt -------------------->
<!-- Remember to chmod 666 (read/write all) count.txt --------->

75

<!--------------- End of count.txt ------------------------->



Good luck ! Saigon 75
minhphuongboy viết 20:18 ngày 09/10/2018
bạn SAIGON75 ơi ! cho mình hỏi : mình có thể nhúng đoạn này vào file.html được hay ko vậy bạn? mình cũng muốn đếm số lượng người truy cặp trang web của minh !
hothanh viết 20:08 ngày 09/10/2018
Ko, mình muốn đếm số người online kỉa ?
normal viết 20:22 ngày 09/10/2018
nếu bạn muốn đếm số người online thì cần đếm có bao nhiêu biến session được đăng kí là OK
quachhylam viết 20:10 ngày 09/10/2018
Nhưng làm thế nào đếm được hả bạn normal
hothanh viết 20:10 ngày 09/10/2018
Tôi muốn tìm kiếm trang web của tôi tại trang google.com (search engine), các bước làm của nó là sao ?
normal viết 20:14 ngày 09/10/2018
đây code đây quachhylam
PHP Code:
session_start(); 

define("MAX_IDLE_TIME"3); 

function 
getOnlineUsers(){ 

if ( 
$directory_handle opendirsession_save_path() ) ) { 
$count 0
while ( 
false !== ( $file readdir$directory_handle ) ) ) { 
if(
$file != '.' && $file != '..'){ 
if(
time()- fileatime(session_save_path() . '\\' $file) < MAX_IDLE_TIME 60) { 
$count++; 


closedir($directory_handle); 

return 
$count

} else { 
return 
false




echo 
"Number of online users: " getOnlineUsers() . "<br />"
Bài liên quan
0