WP-infos 0.3 plugin - how to

September 7, 2006

This plug in is really great, unfortunately this plugin didn’t have a sufficient manual to implement, so here’s the steps you need to take when you want it to show up on your blog.

- Put the wp-infos.php file below your /wp-content/plugins directory.
- Create a table on your WP database
- Put a code on your template (sidebar.php)

Here are the details :
Save this file as wp-infos.php

1. < ?php
2. /*
3. Plugin Name: wp-infos
4. Version: 0.3
5. Plugin URI: http://sebacatalano.altervista.org
6. Description: Show the total visits, the current ip and browser of the user.
7. Author: Seba Catalano
8. Author URI: http://sebacatalano.altervista.org
9. */
10.
11.
12. function wp_infos() {
13.
14. $timeout = "5"; // Timeout, in minutes, to consider a visitor online.
15. $ip = $_SERVER['REMOTE_ADDR']; // Ip of the visitor
16. $browser = $_SERVER['HTTP_USER_AGENT']; // Browser of the visitor
17. $host = $_SERVER['SERVER_NAME']; // Local host name.
18. $referer = $_SERVER['HTTP_REFERER']; // Ref url
19.
20.
21. // Database extraction
22. $query = mysql_query("SELECT * FROM wp_infos WHERE visits != '0'")
23. or die("Error in query: ". mysql_error());
24.
25. $dbarray = mysql_fetch_array($query);
26. $id = $dbarray['id'];
27. $totalcount = $dbarray['visits'];
28. $partialcount = $dbarray['daycount'];
29. $date = $dbarray['daydate'];
30.
31. $online = usr_online($timeout, $ip);
32. counter($id, $totalcount, $partialcount, $host, $date, $referer);
33.
34. // Visualitazion table
35. echo "Total visits: $totalcount
36. Today visits: $partialcount
37. Users online: $online
38. Your IP: $ip
39. Your Browser: $browser";
40. }
41. function usr_online ($timeout, $ip) {
42.
43. $time = time();
44. $less = $time - ($timeout*60);
45.
46. mysql_query("INSERT INTO wp_infos (ip, time) VALUES ('$ip', '$time')") or die("Error in query: ". mysql_error());
47. mysql_query("DELETE FROM wp_infos WHERE time< '$less' AND visits=0") or die("Error in query: ". mysql_error());
48.
49. $query = mysql_query("SELECT COUNT(DISTINCT ip) FROM wp_infos") or die("Error in query: ". mysql_error());
50. $iplist = mysql_fetch_array($query, MYSQL_NUM);
51.
52. return $iplist[0]-1;
53. }
54.
55.
56. function counter ($id, $totalcount, $partialcount, $host, $date, $referer) {
57.
58. // Date
59. $time = getdate();
60.
61. // Vars initialization
62. if (empty($id)) {$id = 0;}
63. if (empty($totalcount)) {$totalcount = 0;}
64. if (empty($partialcount)) {$partialcount = 0;}
65. if (empty($date)) {$date = $time[mday].$time[month];}
66.
67. if (!eregi($host, $referer)) {
68. $totalcount++;
69.
70. if (!strcmp($date, $time[mday].$time[month])) {
71. $partialcount++;
72. }
73. else {
74. $partialcount = 0;
75. $date = $time[mday].$time[month];
76. }
77.
78. // Database entry
79. mysql_query("DELETE FROM wp_infos WHERE visits!=0")
80. or die("Error in query: ". mysql_error());
81.
82. mysql_query("INSERT INTO wp_infos (visits, daycount, daydate) VALUES ($totalcount, $partialcount, '$date')")
83. or die("Error in query: ". mysql_error());
84. }
85. }
86. ?>

You must create a table on your WP database like below (use PHPMyAdmin to do it.)

1. CREATE TABLE `wp_infos` (
2. `id` INT( 10 ) UNSIGNED DEFAULT ‘0‘ NOT NULL AUTO_INCREMENT ,
3. `visits` INT( 20 ) UNSIGNED DEFAULT ‘0‘ NOT NULL ,
4. `daycount` INT( 15 ) UNSIGNED DEFAULT ‘0‘ NOT NULL ,
5. `daydate` VARCHAR( 20 ) NOT NULL ,
6. `ip` VARCHAR(15) NOT NULL,
7. `time` VARCHAR(20) NOT NULL,
8. PRIMARY KEY ( `id` )
9. ) TYPE = MYISAM ;

Last thing you must do is to put code below on your template, usually sidebar.php

1. < ?php if (function_exists('wp_infos')) : ?>
2.
3. < ?php _e('Online'); ?>
4. < ?php wp_infos(''); ?>
5.
6. < ?php endif; ?>

Enjoy,
I hope you like it as much as I do.
Check it out on my site http://www.myonlinebrain.com/biofir

Comments »

The URI to TrackBack this entry is: http://yunar34.blogsome.com/2006/09/07/wp-infos-03-plugin-how-to/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


eXTReMe Tracker