Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2014-11-16 22:36:55 +0300
committerThomas Steur <tsteur@users.noreply.github.com>2014-11-16 22:36:55 +0300
commit0d967aa37142e388f06d490421acb516a28999a2 (patch)
tree12f9c802732a5378391d38daf3460e795bcbbb38 /core/Common.php
parent678b7eabb1498b600b8be244b6c8ec0337c12911 (diff)
parent332af2a3085cf3b35815d1f4b55f9059a627819a (diff)
Merge pull request #6671 from piwik/6661
Throw HTTP 400 error when idsite is invalid
Diffstat (limited to 'core/Common.php')
-rw-r--r--core/Common.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/core/Common.php b/core/Common.php
index a3e7515a24..9bb4108739 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -1150,6 +1150,48 @@ class Common
}
/**
+ * Sends the given response code if supported.
+ *
+ * @param int $code Eg 204
+ *
+ * @throws Exception
+ */
+ public static function sendResponseCode($code)
+ {
+ $messages = array(
+ 200 => 'Ok',
+ 204 => 'No Response',
+ 301 => 'Moved Permanently',
+ 302 => 'Found',
+ 304 => 'Not Modified',
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 500 => 'Internal Server Error'
+ );
+
+ if (!array_key_exists($code, $messages)) {
+ throw new Exception('Response code not supported: ' . $code);
+ }
+
+ if (strpos(PHP_SAPI, '-fcgi') === false) {
+ $key = $_SERVER['SERVER_PROTOCOL'];
+
+ if (strlen($key) > 15 || empty($key)) {
+ $key = 'HTTP/1.1';
+ }
+
+ } else {
+ // FastCGI
+ $key = 'Status:';
+ }
+
+ $message = $messages[$code];
+ Common::sendHeader($key . ' ' . $code . ' ' . $message);
+ }
+
+ /**
* Returns the ID of the current LocationProvider (see UserCountry plugin code) from
* the Tracker cache.
*/