Title: Track Visitors using Codex &amp; jQuery
Last modified: August 20, 2016

---

# Track Visitors using Codex & jQuery

 *  [Archie Makuwa](https://wordpress.org/support/users/archie22is/)
 * (@archie22is)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/track-visitors-using-codex-jquery/)
 * Hi guys,
 * This is what I wish to accomplish:
 * A visitor visits my site and views a post:
    – visitor ip is obtained and stored–
   a counter is added to a database with unique post id
 * But if the visitor views the post again within 24 hours:
    – the counter must 
   not increment – obvisouly this will be based on the fact that the visitor ip 
   address has just been logged in the past 24 hours
 * Again:
    If the visitor view another post: – the same process should occur – store
   ip address and add a counter increment
 * At the moment i have the post displayed as links on the front page, so the script
   i have is run from the links. This will be the case on the site as well… i am
   no so interested in the posts being viewed, but rather on the post links clicked
   from the home page.
 * The script I have is below (not fully functional – the logic is wrong, please
   assist):
 *     ```
       function updateCustomerCount() {
   
       	global $wpdb;
   
       	$post_id = $_POST['id']; // customer id
   
       	// update ip address to reduce redundant click count
       	$remote_ip = $_SERVER['REMOTE_ADDR'];
   
       	if ($remote_ip){
       		$results = $wpdb->get_results("SELECT IP_Address FROM wp_logged_ip WHERE IP_Address="
       				. $remote_ip . "AND CustomerId = ". $post_id . "AND Date = " . date("Y-m-d h:i:s") );
   
       		if(!$results){
       			$wpdb->insert('wp_logged_ip', array('IP_Address' => $remote_ip, 'CustomerId' => $post_id, 'Date' => date("Y-m-d h:i:s")));
   
       			// update customer count
       			$wpdb->insert('wp_customercount', array('customerid' => $post_id, 'date' => date("Y-m-d h:i:s")));
       		}
       	}
   
       }
       ```
   
 * Shout if you need any clarification.

The topic ‘Track Visitors using Codex & jQuery’ is closed to new replies.

## Tags

 * [click count](https://wordpress.org/support/topic-tag/click-count/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Archie Makuwa](https://wordpress.org/support/users/archie22is/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/track-visitors-using-codex-jquery/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
