Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ********* Content of test.html (residing on my computer; registers a hit when viewed in my browser and image rendered.):
- <img src="http://example.com/img.png" alt="img" />
- ********* 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!):
- <!DOCTYPE html>
- <html>
- <body>
- <img src="http://example.com/img.png" alt="img" />
- </body>
- </html>
- ********* Content of .htaccess (residing on my webhost ~user/public_html/.htaccess):
- # Use PHP 5.3
- AddType application/x-httpd-php53 .php
- RewriteEngine On
- RewriteRule img.png img.php
- # comment ....
- <IfModule mod_suphp.c>
- suPHP_ConfigPath /home/user
- <Files php.ini>
- order allow,deny
- deny from all
- </Files>
- </IfModule>
- ********* Content of img.php (residing on my webhost ~user/public_html/img.php):
- <?php
- //Set the id of your piwik site here
- $idSite = 1;
- $token_auth = 'secret';
- //Load Piwik Tracker
- require_once 'PiwikTracker.php';
- //Set the URL path to your Piwik Installation
- $t = new PiwikTracker($idSite,'http://example.com/analytics/');
- //Auth to allow for more API functions
- $t->setTokenAuth($token_auth);
- //Set correct IP (Should be users, not the web server issuing the request)
- $t->setIp($_SERVER['REMOTE_ADDR']);
- //Set referrer (if applicable)
- if(isset($_SERVER['HTTP_REFERER']))
- $t->setUrl($_SERVER['HTTP_REFERER']);
- //Do the tracking
- $t->doTrackPageView('Image viewed!');
- //Get image to be returned
- $im = imagecreatefrompng("img.png");
- //For transparency (Alpha blending)
- imagealphablending($im, true);
- imagesavealpha($im, true);
- //Set header
- header('Content-Type: image/png');
- //Output image
- imagepng($im);
- //Unload image
- imagedestroy($im);
- ?>
- ********* PiwikTracker.php (residing on my webhost ~user/public_html/PiwikTracker.php)
- ********* img.png (residing on my webhost ~user/public_html/img.png)
- ********* piwik.php et.al. (residing on my webhost ~user/public_html/analytics/piwik.php)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement