Wordpress website access statistics

Source: Internet
Author: User
Tags explode flock

Principle analysis

The method is simple. Add js and php code to the wordpress header and bottom. Let's take a step-by-step example.

Add to footer. php

The code is as follows: Copy code

<Span class = 'online'> </span>

Add header. php

The code is as follows: Copy code

$ (Function () {$ (". online"). load ("/vis. php ");

Finally, save the following code as a vis. Php file in the root directory of your website.

The code is as follows: Copy code

<? Php

$ User_online = "count. php"; // The number of objects that are stored
Touch ($ user_online); // If this file is not available, create
$ Timeout = 30; // The author is not moved within 30 seconds.
$ User_arr = file_get_contents ($ user_online );
$ User_arr = explode ('#', rtrim ($ user_arr, '#'); print_r ($ user_arr );
$ Temp = array ();
Foreach ($ user_arr as $ value ){
$ User = explode (",", trim ($ value ));
If ($ user [0]! = Getenv ('remote _ ADDR ') & ($ user [1]> time ())) {// if the user's IP address does not time out, it will be placed in the array
Array_push ($ temp, $ user [0]. ",". $ user [1]);
}
}
Array_push ($ temp, getenv ('remote _ ADDR '). ",". (time () + ($ timeout )). '#'); // save the user's information
$ User_arr = implode ("#", $ temp );
// Write a file
$ Fp = fopen ($ user_online, "w ");
Flock ($ fp, LOCK_EX); // flock () cannot work normally in NFS or some other network file systems
Fputs ($ fp, $ user_arr );
Flock ($ fp, LOCK_UN );
Fclose ($ fp );
Echo "currently". count ($ temp). "online ";
?>

So you can see if there will be online users. Of course, we can also use statistics like webmasters, Baidu Statistics, and so on. They can also directly open online users, this method is easy to add. Here is a brief introduction.

How to add third-party Statistics

Also add the statistical code you obtained in webmaster statistics or Baidu Statistics to footer. php in your wordpress footer. php.

Place it in that location without code demonstration.

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.