Piwik\Common::sendResponseCode PHP Method

sendResponseCode() public static method

Sends the given response code if supported.
public static sendResponseCode ( integer $code )
$code integer Eg 204
    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', 503 => 'Service Unavailable');
        if (!array_key_exists($code, $messages)) {
            throw new Exception('Response code not supported: ' . $code);
        }
        if (strpos(PHP_SAPI, '-fcgi') === false) {
            $key = 'HTTP/1.1';
            if (array_key_exists('SERVER_PROTOCOL', $_SERVER) && strlen($_SERVER['SERVER_PROTOCOL']) < 15 && strlen($_SERVER['SERVER_PROTOCOL']) > 1) {
                $key = $_SERVER['SERVER_PROTOCOL'];
            }
        } else {
            // FastCGI
            $key = 'Status:';
        }
        $message = $messages[$code];
        Common::sendHeader($key . ' ' . $code . ' ' . $message);
    }

Usage Example

Esempio n. 1
0
 /**
  * Echos an error message & other information, then exits.
  *
  * @param Tracker $tracker
  * @param Exception $e
  * @param int  $statusCode eg 500
  */
 public function outputException(Tracker $tracker, Exception $e, $statusCode)
 {
     Common::sendResponseCode($statusCode);
     $this->logExceptionToErrorLog($e);
     $result = $this->formatException($tracker, $e);
     echo json_encode($result);
 }
All Usage Examples Of Piwik\Common::sendResponseCode