PiwikTracker.php on request return login page

Hi, I have a problem with PiwikTracker:


$piwikTracker = new PiwikTracker(1);
$host = isset($_GET['host']) ? $_GET['host']: 'unknown';
$piwikTracker->setCustomVariable(1, 'site', $host);
$piwikTracker->setCustomVariable(2, 'block', @$_GET['bid']);
$piwikTracker->doTrackPageView('show');

Response on this $piwikTracker->doTrackPageView is login page


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>Piwik &rsaquo; Sign in</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="plugins/CoreHome/templates/images/favicon.ico" />
<link rel="stylesheet" type="text/css" href="plugins/Login/templates/login.css?cb=ec863ceee7c05880d38ab5882ee97e2a" />
<meta name="description" content="Open Source Web Analytics" />
<script type="text/javascript">
                function focusit() {
                        var formLogin = document.getElementById('form_login');
                        if(formLogin)
                        {
                                formLogin.focus();
                        }
                }
                window.onload = focusit;
        </script>
<script type="text/javascript" src="libs/jquery/jquery.js?cb=ec863ceee7c05880d38ab5882ee97e2a"></script>
<style type="text/css">body { display : none; }</style>
</head>
<body class="login">
<script type="text/javascript">if(self == top) { var theBody = document.getElementsByTagName('body')[0];        theBody.style.display = 'block'; } else { top.location = self.location; }</script>
<!--[if lt IE 7]> <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative; text-align:center;'> <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://www.theie6countdown.com/images/upgrade.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /></a></div> <![endif]-->      <div id="logo">
<a href="http://piwik.org" alt="Piwik" title="Web analytics">           <img src='http://mydomain.ru/themes/default/images/logo.png' title="Web analytics" width='200' style='margin-right:20px' />
<div class="description"># Web analytics</div>
</a>    </div>
<div id="login">
<form  action="?idsite=1&rec=1&apiv=1&r=649470&cip=159.255.35.51&_id=f813842a32c57c32&_cvar=%7B%221%22%3A%5B%22site%22%2C%22mydomain2.ru%22%5D%2C%222%22%3A%5B%22block%22%2C%221640%22%5D%7D&url=http%3A%2F%2Fmydomain.ru%2Fplatform%2FRenderer%2FDefault%2F%3Fbid%3D1640%26host%3Dmydomain2.ru&urlref=http%3A%2F%2Fmydomain2.ru%2Frus%2Finfo%2F51057&action_name=show" name="loginform" id="loginform" method="post">
<p>
<label>Username:<br />
<input type="text" name="form_login" id="form_login" class="input" value="" size="20" tabindex="10" />
<input type="hidden" name="form_nonce" id="form_nonce" value="53e7d2d42b638456a3ed52a0590e2e94" /></label>
</p>
<p>
<label>Password:<br />
<input type="password" name="form_password" id="form_password" class="input" value="" size="20" tabindex="20" /></label>
</p>
<p class="forgetmenot">
<label><input name="form_rememberme" type="checkbox" id="form_rememberme" value="1" tabindex="90" /> Remember Me </label>
</p>
<p class="submit">
<input type="submit" value="Sign in" tabindex="100" />
</p>
</form>
<p id="nav">
<a href="index.php?module=Login&action=lostPassword" title="Lost your password?">Lost your password?</a>
</p>
</div>
</body>
</html>

My code works on localhost, development server, but in production I have this result. The only difference of installations is that on dev and local machines using PDO and on production mysqli.

Comment please how to find solution.

Thanks,

Roman Levishchenko

I tried with setting auth_token


$piwikTracker = new PiwikTracker(1);
$piwikTracker->setTokenAuth($token_auth);
$host = isset($_GET['host']) ? $_GET['host']: 'unknown';
$piwikTracker->setCustomVariable(1, 'site', $host);
$piwikTracker->setCustomVariable(2, 'block', @$_GET['bid']);
$piwikTracker->doTrackPageView('show');

Result in this case is 302 status

Change

$piwikTracker = new PiwikTracker(1);

to

$piwikTracker = new PiwikTracker(1, ‘http://piwik-server.com/piwik/’);

Tnx, matt.
I fogot to write the line in this post:


PiwikTracker::$URL = $config['piwikUrl'];

However, problem still exists(((

result of curl_exec(); in PiwikTracker::getRequest


http://mydomain.ru//piwik.php?idsite=1&rec=1&apiv=1&r=039279&cip=92.124.87.43&_id=b16edaa4fb6a6054&token_auth=f12df90dbe1*********************&_cvar=%7B%221%22%3A%5B%22site%22%2C%22mydomain2.ru%22%5D%2C%222%22%3A%5B%22block%22%2C%221640%22%5D%7D&url=http%3A%2F%2Fmydomain.ru%2Fplatform%2FRenderer%2FDefault%2F%3Fbid%3D1640%26host%3Dmydomain2.ru&urlref=http%3A%2F%2Fmydomain2.ru%2Frus%2Finfo%2F44162

result of curl_exec(); in PiwikTracker::sendRequest


HTTP/1.1 302 Found
Server: nginx/1.1.19
Date: Wed, 05 Sep 2012 06:22:13 GMT
Content-Type: text/html
Content-Length: 0
Connection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.2
Set-Cookie: PIWIK_SESSID=epm3q0l3sl8qjpt8e37s2fpdf4; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: index.php?module=CoreHome&action=index&idSite=1&period=day&date=today
Vary: Accept-Encoding


wget -qO- "http://mydomain.ru//piwik.php?idsite=1&rec=1&apiv=1&r=039279&cip=92.124.87.43&_id=b16edaa4fb6a6054&token_auth=f12df90dbe1*********************&_cvar=%7B%221%22%3A%5B%22site%22%2C%22mydomain2.ru%22%5D%2C%222%22%3A%5B%22block%22%2C%221640%22%5D%7D&url=http%3A%2F%2Fmydomain.ru%2Fplatform%2FRenderer%2FDefault%2F%3Fbid%3D1640%26host%3Dmydomain2.ru&urlref=http%3A%2F%2Fmydomain2.ru%2Frus%2Finfo%2F44162"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Piwik &rsaquo; Error</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="plugins/CoreHome/templates/images/favicon.ico" />
	<link rel="stylesheet" type="text/css" href="themes/default/simple_structure.css" />
</head>
<body id="simple">
<div id="contentsimple">
	<div id="title"><img title='Piwik' alt="Piwik" src='themes/default/images/logo-header.png' style='margin-left:10px' /><span id="subh1"> # <a href='http://piwik.org/'>Web Analytics</a></span></div>
<p>The requested website idSite is not found in the request, or is invalid.
				Please check that you are logged in Piwik and have permission to access the specified website.</p>
				<p><a href="index.php">Go to Piwik</a><br/>
				<a href="index.php?module=Login">Login</a></p>
				 </div>
</body>
</html>

The requested website idSite is not found in the request, or is invalid.
I changed request url: &idsite -> &idSite. // result is the same

idSite = 1 - right

The problem was in apache config. All request went to index.php