/**
     * Send this HTTPReponse to the browser
     */
    public function output()
    {
        // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
        if (Director::is_ajax()) {
            Requirements::include_in_response($this);
        }
        if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
            $url = Director::absoluteURL($this->headers['Location'], true);
            $urlATT = Convert::raw2htmlatt($url);
            $urlJS = Convert::raw2js($url);
            $title = Director::isDev() ? "{$urlATT}... (output started on {$file}, line {$line})" : "{$urlATT}...";
            echo <<<EOT
<p>Redirecting to <a href="{$urlATT}" title="Click this link if your browser does not redirect you">{$title}</a></p>
<meta http-equiv="refresh" content="1; url={$urlATT}" />
<script type="text/javascript">setTimeout(function(){
\twindow.location.href = "{$urlJS}";
}, 50);</script>";
EOT;
        } else {
            $line = $file = null;
            if (!headers_sent($file, $line)) {
                header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
                foreach ($this->headers as $header => $value) {
                    header("{$header}: {$value}", true, $this->statusCode);
                }
            } else {
                // It's critical that these status codes are sent; we need to report a failure if not.
                if ($this->statusCode >= 300) {
                    user_error("Couldn't set response type to {$this->statusCode} because " . "of output on line {$line} of {$file}", E_USER_WARNING);
                }
            }
            // Only show error pages or generic "friendly" errors if the status code signifies
            // an error, and the response doesn't have any body yet that might contain
            // a more specific error description.
            if (Director::isLive() && $this->isError() && !$this->body) {
                Debug::friendlyError($this->statusCode, $this->getStatusDescription());
            } else {
                echo $this->body;
            }
        }
    }
Esempio n. 2
0
 /**
  * Send this HTTPReponse to the browser
  */
 function output()
 {
     // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
     if (Director::is_ajax()) {
         Requirements::include_in_response($this);
     }
     if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
         $url = $this->headers['Location'];
         echo "<p>Redirecting to <a href=\"{$url}\" title=\"Please click this link if your browser does not redirect you\">{$url}... (output started on {$file}, line {$line})</a></p>\n\t\t\t<meta http-equiv=\"refresh\" content=\"1; url={$url}\" />\n\t\t\t<script type=\"text/javascript\">setTimeout('window.location.href = \"{$url}\"', 50);</script>";
     } else {
         if (!headers_sent()) {
             header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
             foreach ($this->headers as $header => $value) {
                 header("{$header}: {$value}");
             }
         }
         if (Director::isLive() && $this->isError()) {
             Debug::friendlyError($this->statusCode, $this->getStatusDescription());
         } else {
             echo $this->body;
         }
     }
 }
Esempio n. 3
0
 /**
  * Send this HTTPReponse to the browser
  */
 public function output()
 {
     // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
     if (Director::is_ajax()) {
         Requirements::include_in_response($this);
     }
     if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
         $url = $this->headers['Location'];
         echo "<p>Redirecting to <a href=\"{$url}\" title=\"Click this link if your browser does not redirect you\">" . "{$url}... (output started on {$file}, line {$line})</a></p>\n\t\t\t<meta http-equiv=\"refresh\" content=\"1; url={$url}\" />\n\t\t\t<script type=\"text/javascript\">setTimeout('window.location.href = \"{$url}\"', 50);</script>";
     } else {
         if (!headers_sent()) {
             header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
             foreach ($this->headers as $header => $value) {
                 header("{$header}: {$value}", true, $this->statusCode);
             }
         }
         // Only show error pages or generic "friendly" errors if the status code signifies
         // an error, and the response doesn't have any body yet that might contain
         // a more specific error description.
         if (Director::isLive() && $this->isError() && !$this->body) {
             Debug::friendlyError($this->statusCode, $this->getStatusDescription());
         } else {
             echo $this->body;
         }
     }
 }