WordPress.org

Ready to get started?Download WordPress

Forums

Mechanic Visitor Counter
BUG: primary key should be on ip AND tanggal fields ! (10 posts)

  1. Jack All
    Member
    Posted 1 year ago #

    Lot of errors in this vistor counter:
    1. if visitor returns next day his ip wont get inserted cause its a primary key -> solution: set the primary key on ip AND tanggal fields in phpMyAdmin - mysql
    2. images link to demo site -> solution: change line 139 to local path
    3. images in admin do not show right, remove breaks between <img> tags
    4. some counters are showing ugly numbers caused bij transparent color -> solution: save image in same type but deselect transparency
    5. some markup closed in error or not at all

    Changes are made in wp-statsmechanic.php
    after that it runs like a charm

    http://wordpress.org/extend/plugins/mechanic-visitor-counter/

  2. Dynadata
    Member
    Posted 1 year ago #

    Thanks alot for fix 1.
    this fix also fixes a bug that does not allow the counter to increase on different IPs. (for example I went to the site and the counter increases as expected, but my client (different IP) goes to the site and the counter does not increase)

  3. Jack All
    Member
    Posted 1 year ago #

    You're right as of v 2.7 the primairy key is on date (tanggal) field only, instead of ip AND date (tanggal) fields.
    This causes a returning visitor on the same day not being counted.

    This issue still isn't solved in v2.8.
    I notified the author two times already but didn't get a response, so I'm posting it here.

  4. mteguhsat
    Member
    Posted 11 months ago #

    Hi Jack,

    I choose to modify the code, instead of changing the primary key. I keep the ip column as the primary key, but from the code I change the format in ip column to be "$ip/$tanggal", so new entry will be recorded if the same ip is visiting in different date (tanggal). For me, this way works well and fix the counter stop issue. In my case, I only need information about Today Visit, Yesterday, Total Visit, and Total Hints. I'm not sure about other stuff, but if anybody wanna give a try, follow this:

    Find these lines:

    // Check your IP, whether the user has had access to today's
                  $sql = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ip' AND tanggal='$tanggal'");
                  // If not there, save the user data to the database
                  if(mysql_num_rows($sql) == 0){
                    mysql_query("INSERT INTO <code>". BMW_TABLE_NAME . "</code>(ip, tanggal, hits, online) VALUES('$ip','$tanggal','1','$waktu')");
                  }
                  else{
                    mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ip' AND tanggal='$tanggal'");
                  }

    and then replace with

    // ---- modified by parasatria.me
    	      // Get ipx = ip + tanggal, as new format for primary key
    	      $ipx = $ip."/".$tanggal;
    	      // Check if the ip has ever visit before
    	      $sql = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ip'");
    	      // if never visit us before, check the ipx
    	      if (mysql_num_rows($sql) == 0){
    		// Check if the ipx has ever visit before
    		$sql3 = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ipx'");
    		// if the ipx never visit us before, add new entry with new format key, else update entries
    		if (mysql_num_rows($sql3) == 0){
    			mysql_query("INSERT INTO <code>". BMW_TABLE_NAME . "</code>(ip, tanggal, hits, online) VALUES('$ipx','$tanggal','1','$waktu')");
    		} else {
    			mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ipx'");
    		}
    	      } else {
    		// Check if the ip was visiting at the same date
    		$sql2 = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ip' AND tanggal='$tanggal'");
    		// if it's not at the same date, check the ipx, else update entries
    		if (mysql_num_rows($sql2) == 0){
    			// Check if the ipx has ever visit before
    			$sql3 = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ipx'");
    			// if the ipx never visit us before, add new entry with new format key, else update entries
    			if (mysql_num_rows($sql3) == 0){
    				mysql_query("INSERT INTO <code>". BMW_TABLE_NAME . "</code>(ip, tanggal, hits, online) VALUES('$ipx','$tanggal','1','$waktu')");
    			} else {
    				mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ipx'");
    			}
    		} else {
    			mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ip' AND tanggal='$tanggal'");
    		}
    	      }
    	      // ---- end of modification, by parasatria.me
  5. mteguhsat
    Member
    Posted 11 months ago #

    In previous code, I was trying to maintain the existing entries, but then I realized some lines were not necessary.

    So, actually, it can be more simple with this version:

    // ---- modified by parasatria.me
    // Get ipx = ip + tanggal, as new format for primary key
    $ipx = $ip."/".$tanggal;
    // Check if the ipx has ever visit before
    $sql = mysql_query("SELECT * FROM <backticks>". BMW_TABLE_NAME . "<backticks> WHERE ip='$ipx'");
    // if the ipx never visit us before, add new entry with new format key, else update entries
    if (mysql_num_rows($sql) == 0){
    mysql_query("INSERT INTO <backticks>". BMW_TABLE_NAME . "<backticks>(ip, tanggal, hits, online) VALUES('$ipx','$tanggal','1','$waktu')");
    } else {
    mysql_query("UPDATE <backticks>". BMW_TABLE_NAME . "<backticks> SET hits=hits+1, online='$waktu' WHERE ip='$ipx'");
    }
    // ---- end of modification, by parasatria.me

    Note: replace <backticks> with backticks character

  6. oceanfear
    Member
    Posted 11 months ago #

    My counter visit today part always show 1?
    Any idea?

  7. mteguhsat
    Member
    Posted 11 months ago #

    have you tried Jack's solution: "set the primary key on ip AND tanggal fields in phpMyAdmin - mysql" ?

    or, do you want to hack the code instead like I did? :D

  8. mteguhsat
    Member
    Posted 11 months ago #

    ah, I forgot to tell.. if you follow my code, you have to modify the size of ip column in SQL.. by default, the ip is varchar(20) and it's not enough.. so, you need to set is as varchar(30).. you can modify it through phpMyAdmin..

  9. oceanfear
    Member
    Posted 11 months ago #

    How can ı set the primary key on ip AND tanggal fields in phpMyAdmin.
    Can you explain more detailed.
    I dont know much about phpmyadmin.

  10. cornelius6
    Member
    Posted 10 months ago #

    Hi,

    Could you, please, write the code to fix the error as Jack described in point 1?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic