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.