Advertisement
Guest User

Piwik-18.10.2013

a guest
Oct 18th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. ********* Content of test.html (residing on my computer; registers a hit when viewed in my browser and image rendered.):
  2. <img src="http://example.com/img.png" alt="img" />
  3.  
  4.  
  5. ********* Content of test.html (residing on my webhost ~user/public_html/test.html, no hit when surfing there via example.com/test.html, BUT imgage is rendered!):
  6. <!DOCTYPE html>
  7. <html>
  8. <body>
  9.  
  10. <img src="http://example.com/img.png" alt="img" />
  11.  
  12. </body>
  13. </html>
  14.  
  15.  
  16. ********* Content of .htaccess (residing on my webhost ~user/public_html/.htaccess):
  17. # Use PHP 5.3
  18. AddType application/x-httpd-php53 .php
  19.  
  20. RewriteEngine On
  21. RewriteRule img.png img.php
  22.  
  23. # comment ....
  24.  
  25. <IfModule mod_suphp.c>
  26.  suPHP_ConfigPath /home/user
  27.  <Files php.ini>
  28.    order allow,deny
  29.    deny from all
  30.  </Files>
  31. </IfModule>
  32.  
  33.  
  34.  
  35. ********* Content of img.php  (residing on my webhost ~user/public_html/img.php):  
  36. <?php
  37.     //Set the id of your piwik site here
  38.     $idSite = 1;
  39.     $token_auth = 'secret';
  40.  
  41.     //Load Piwik Tracker
  42.     require_once 'PiwikTracker.php';
  43.  
  44.     //Set the URL path to your Piwik Installation
  45.     $t = new PiwikTracker($idSite,'http://example.com/analytics/');
  46.  
  47.     //Auth to allow for more API functions
  48.     $t->setTokenAuth($token_auth);
  49.  
  50.     //Set correct IP (Should be users, not the web server issuing the request)
  51.     $t->setIp($_SERVER['REMOTE_ADDR']);
  52.  
  53.     //Set referrer (if applicable)
  54.     if(isset($_SERVER['HTTP_REFERER']))
  55.        $t->setUrl($_SERVER['HTTP_REFERER']);
  56.  
  57.     //Do the tracking
  58.     $t->doTrackPageView('Image viewed!');
  59.  
  60.     //Get image to be returned
  61.     $im = imagecreatefrompng("img.png");
  62.  
  63.     //For transparency (Alpha blending)
  64.     imagealphablending($im, true);
  65.     imagesavealpha($im, true);
  66.  
  67.     //Set header
  68.     header('Content-Type: image/png');
  69.     //Output image
  70.     imagepng($im);
  71.     //Unload image
  72.     imagedestroy($im);
  73. ?>
  74.  
  75. ********* PiwikTracker.php  (residing on my webhost ~user/public_html/PiwikTracker.php)
  76.  
  77. ********* img.png  (residing on my webhost ~user/public_html/img.png)
  78.  
  79. ********* piwik.php et.al. (residing on my webhost ~user/public_html/analytics/piwik.php)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement