The < i_am_super_user > Property

Although I have had little trouble making report requests to the Matomo program via HTTP requests, I am having enormous trouble in my effort to access the same directly via PHP.

I copied, with some modification, the sample code (see below) provided by Matomo into a file. When I try to open the file, however, I am confronted with the following error message.

Please contact the system administrator, or login to Matomo to learn more.

If you are Super User, but cannot login because of this error, you can still troubleshoot further. Follow these steps:
1) open the config/config.ini.php file and look for the salt value under [General].
2) edit this current URL you are viewing and add the following text (replacing salt_value_from_config by the salt value from the config file):

index.php?i_am_super_user=salt_value_from_config&....

Following this advice does not resolve the problem, however.

The ERROR MESSAGE

Please contact the system administrator, or login to Matomo to learn more.

If you are Super User, but cannot login because of this error, you can still troubleshoot further. Follow these steps:

  1. open the config/config.ini.php file and look for the salt value under [General].
  2. edit this current URL you are viewing and add the following text (replacing salt_value_from_config by the salt value from the config file):

index.php?i_am_super_user=salt_value_from_config&…

The CODE

<?php
    ini_set('log_errors', 1);
    ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');
    ini_set('html_errors', 0);
    ini_set('display_errors', 0);
    error_reporting(E_ALL);

    use Matomo\API\Request;
    use Matomo\FrontController;

    define('PIWIK_INCLUDE_PATH', realpath('my_path'));
    define('PIWIK_USER_PATH', realpath('my_path'));
    define('PIWIK_ENABLE_DISPATCH', false);
    define('PIWIK_ENABLE_ERROR_HANDLER', false);
    define('PIWIK_ENABLE_SESSION_START', false);

    require_once PIWIK_INCLUDE_PATH . "/index.php";
    require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";

    $environment = new \Piwik\Application\Environment(null);
    $environment->init();

    FrontController::getInstance()->init();

    // This inits the API Request with the specified parameters
    $request = new Request('
                module=API
                &method=Resolution.getResolution
                &idSite=1
                &date=yesterday
                &period=week
                &format=original
                &filter_limit=3
    ');
    // Calls the API and fetch XML data back
    $result = $request->process();
    echo $result;
?>

Any suggestions about how to implement PHP Direct?

Roddy

Might this from Matomo automatically generated .htaccess file be the source of the problem?

<Files "*">
<IfModule mod_version.c>
    <IfVersion < 2.4>
        Order Deny,Allow
        Deny from All
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</IfModule>
<IfModule !mod_version.c>
    <IfModule !mod_authz_core.c>
        Order Deny,Allow
        Deny from All
    </IfModule>
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
</IfModule>
</Files>

Roddy

Insofar as Matomo has a reputation on the internet of being resource-intensive it would seem that users would avoid the use of endless HTTP requests to communicate with the Reporting API.

Is there really no one in all of these forums who uses direct access to the index.php file?

Roddy

Just a guess… is there a &token_auth=YOURTOKENAUTH missing?

Also I would recommend you create HTTP requests to fetch data from the API and not bootstrap Matomo. I don’t know where we mention this example but IMO it should be removed.

Have a look here: Tutorial: Get your top 10 keywords: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 and the first example in Querying the Reporting API: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 as well as the reference Reporting API Reference: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 instead.

I noticed the example is from Querying the Reporting API: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 and I will suggest to remove the second example.

Yes, I did include an authentication token in my request statement, but I am surprised by your response.

My surprise is that you would recommend HTTP requests over direct PHP commands. Matomo has a reputation on the internet for being resource-intensive, and repeated HTTP requests can only exaggerate the number of resources. On the other hand, I have been very successful with cURL as was recommended by Fabian already several weeks ago.

I am currently under pressure by my host server to move to the cloud via VPS, as Matomo is overextending my welcome on the shared server that I occupy.

Roddy

p.s. Thanks for the many suggested links. I will continue to explore.

I have discovered the source of my problem. Both my site and Matomo lie in the same root directory, albeit in different folders along very different paths.

PROBLEM SOURCE: /config/.htaccess

FILE CONTENTS:

<Files "*">

    <IfModule mod_version.c>
        <IfVersion < 2.4>
              Order Deny,Allow
              Deny from All
        </IfVersion>
        <IfVersion >= 2.4>
             Require all denied
        </IfVersion>
    </IfModule>

    <IfModule !mod_version.c>
        <IfModule !mod_authz_core.c>
            Order Deny,Allow
            Deny from All
        </IfModule>
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
    </IfModule>
</Files>

QUESTION:

My question to the forum is how to adjust it in such a way that security is not jeopardized.

Roddy