Search code examples
phpanalyticsmatomo

How can piwik get original URL when showed as img


Piwik (alternative to Google Analytics) tracks visits of pages when javascript is off via this code:

<noscript><p><img src="http://piwik-server.com/piwik.php?idsite=1&rec=1" style="border:0" alt="" /></p></noscript>

This code is enough for piwik to log the origianl URL. So for example if this code is on page http://example.com/some-path.html , the piwik.php script will be able to log the URL "http://example.com/some-path.html" even though the javascript is off. I would say that the piwik.php is downloaded separately via another GET request and no origianl URL is passed to the script, so this should be impossible - which is obviously not. How is it able to do that?


Solution

  • I think I figured it out, it can be done via $_SERVER['HTTP_REFERER']. No magic here :).