Advertisement
ellisgl

Piwik Image Tracker

Feb 7th, 2012
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2. //Set the id of your piwik site here
  3. $idSite     = 1;
  4. $token_auth = 'your user token here';
  5. $img        = 'stat.png';
  6.  
  7. //Load Piwik Tracker
  8. require_once 'PiwikTracker.php';
  9.  
  10. //Set the URL path to your Piwik Installation
  11. $t          = new PiwikTracker($idSite, 'http://strainplumbing.com/piwik');
  12.  
  13. //Auth to allow for more API functions
  14. $t->setTokenAuth($token_auth);
  15.  
  16. //Set correct IP (Should be users, not the web server issuing the request)
  17. $t->setIp($_SERVER['REMOTE_ADDR']);
  18.  
  19. //Set referrer (if applicable)
  20. if(isset($_SERVER['HTTP_REFERER']))
  21. {
  22.     $t->setUrl($_SERVER['HTTP_REFERER']);
  23. }
  24.  
  25. $t->doTrackPageView('Strain Plumbing');
  26.  
  27. if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($img))
  28. {
  29.     header('Last-modified: '.date(DATERFC_1123, filemtime($img)), true, 304);
  30.     exit;
  31. }
  32.  
  33.  
  34. //Set header
  35. header('Content-Type: image/png');
  36. header('Expires: '.date(DATE_RFC1123, time()+2592000));
  37. header('Last-modified: '.date(DATE_RFC1123, filemtime($img)));
  38.  
  39. //Output image
  40. echo file_get_contents($img);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement