PHP Simple statistics on the number of people online method

Source: Internet
Author: User
Tags flock getting started with php
This article is an example of PHP simple statistics online number of methods. Share to everyone for your reference, as follows:

<?php//first you have to read and write the permissions of the file//This program can be run directly, the first error, to fou smear shoot? $online _log = "Count.dat"; Save the number of files, $timeout = 30;//30 seconds not moving the author, think the drop line $entries = file ($online _log); $temp = Array (); for ($i =0; $i time
 
  
   
   ()) {  Array_push ($temp, $entry [0]. ",". $entry [1]. " \ n "); Remove the information from other visitors and remove the timeout, and save it in $temp}}array_push ($temp, getenv (' remote_addr '). ",". ( Time () + ($timeout)). " \ n "); Update the browser time $users_online = count ($temp); Calculate the number of online $entries = Implode ("", $temp);//write File $fp = fopen ($online _log, "w"); Flock ($fp, LOCK_EX); Flock () cannot work properly in NFS and some other network file systems Fputs ($FP, $entries), Flock ($FP, Lock_un), fclose ($FP), echo "current". $users _online. " People online ";? >
 
  

How to use:

Save the above code as count.php, in the location you want to use:

Include ("count.php");

More about PHP related content readers can view the topic: "PHP File Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document tips summary (including word, excel,access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

The above describes the PHP simple statistics on the number of online methods, including PHP, the content of the method, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.