Could some please explain how to initiate a login to Piwik via API or using internal functions? From my external webapp I am using try to use login.logme module/action however it is not apart of the API. I know what I am trying to achieve shouldn’t be that difficult.<?php // if you don't include 'index.php', you must also define PIWIK_DOCUMENT_ROOT // and include "libs/upgradephp/upgrade.php" and "core/Loader.php" define('PIWIK_INCLUDE_PATH', realpath('../console/analytics')); define('PIWIK_USER_PATH', realpath('../console/analytics')); 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"; Piwik_FrontController::getInstance()->init(); // This inits the API Request with the specified parameters $request = new Piwik_API_Request(' method=Login.logme &login=admin &password=8b33705980b1002bdf78f42ebb1ddd22 '); // Calls the API and fetch XML data back $result = $request->process(); echo $result;
The API is stateless, session-less. That’s why token_auth has to be passed in some cases.
Does this work?
$_GET['login'] = 'admin'; $_GET['password'] = '#####'; $controller = new Piwik_Login_Controller(); $controller->logme();
@Anthon I now understand what you mean with the API being session-less - what I was trying to achieve would never have worked.
Your recommendation worked (when not using the super admin of course) however only when the script is run in the PIWIK root directory. If I try running the script from say the other webapp location than it doesn’t work and I believe it is because of either the session &/or auth cookie. The session cookie is called ‘PHPSESSID’ as opposed to ‘PIWIK_SESSID’ and the path of the ‘piwik_auth’ is the path of the other webapp as opposed to PIWIK. Have you ever dealt with an issue like this before?
I’d like to buy you a beer if you can give me another clue on this one.