CaRP Evolution Documentation
CaRP Evolution Documentation
twitter youtube linkedin google-plus
CaRP Evolution Box
Web This Site

CaRP: Caching RSS Parser - Documentation


CaRP Interactive FAQ
Getting Started: Free Download | Purchase | Install
Reference: Functions | Plugins | Themes | Full Index
Etc.: Display Formatting | Example Code | Affiliates

Click

Click is a plugin bundled with CaRP Evolution version 4.0.4 and higher. It enables you to route clicks to the channel and item title links through any URL. You could use it to, for example, track how many times each headline is clicked. (You should always redirect the reader from your tracking script to the original link target.)
 
Installation:
To install Click, put click.php into the "plugins" folder inside the folder containing carp.php. (If no plugins folder exists, create one.)
 
Use:
To use this plugin, enter code like the following into your webpage after "require_once '/path/to/carp.php';": CarpLoadPlugin('click.php');
$clickcarpconf['target']='http://example.com/goto.php?q=';
The second line should contain the URL that you want the clicks to go through. The original link target will be added to the end of the URL, so it should always include a "query string" (the question mark and everything after it).

The following code is an example of what might appear in "goto.php" (or whatever you name your file): <?php
header('HTTP/1.0 302 Moved Permanently');
header('Location: '.stripslashes($_GET['q']));
header('Expires: 0');

if (mysql_connect('localhost','username','password')) {
   mysql_select_db('mydatabase');
   if (mysql_query('update trackingtable set clicks=clicks+1 where urlhash="'.md5($_GET['q']).'"')) {
      if (!mysql_affected_rows())
         mysql_query('insert into trackingtable set clicks=1, url="'.$_GET['q'].'", urlhash="'.md5($_GET['q']).'"');
   }
}
?>
The first two lines tell the reader's web browser to go to the original link that was taken from the feed. A "302" or permanent redirect is used so that the original link target gets credit for the inbound link -- this is essentially how you "pay" the content creator for the use of their content.

The third line (the "Expires" header) ensures that if the same reader clicks the same link again, their browser will visit your tracking script so that you can count the click again before they go on to the final link target.

The MySQL code connects to your database and attempts to update the click count for the URL that was clicked. If the update fails (mysql_affected_rows = 0), it assumes that the failure occurred because no clicks have been recorded for that link yet, so it's not in the database. In that case, it inserts a new record into the database for that link.

The reason for using the MD5 hash of the URL is to minimize the length of the text that MySQL has to search for to find the record to be updated. An MD5 hash is always 32 characters long, but a URL could be virtually any length. So "urlhash" could be a "char(32)" field. "url" should probably be a "text" field.