本文整理汇总了PHP中Zend_Controller_Response_Http::sendHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Response_Http::sendHeaders方法的具体用法?PHP Zend_Controller_Response_Http::sendHeaders怎么用?PHP Zend_Controller_Response_Http::sendHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Controller_Response_Http
的用法示例。
在下文中一共展示了Zend_Controller_Response_Http::sendHeaders方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Send the file to the client (Download)
*
* @param string|array $options Options for the file(s) to send
* @return void
*/
public function send($options = null)
{
if (is_string($options)) {
$filepath = $options;
} else {
if (is_array($options)) {
$filepath = $options['filepath'];
} else {
throw new Exception("Filename is not set.");
}
}
if (!is_file($filepath) || !is_readable($filepath)) {
throw new Exception("File '{$filepath}' does not exists.");
}
$mimeType = $this->_detectMimeType(array('name' => $filepath));
$response = new Zend_Controller_Response_Http();
$response->setHeader('Content-length', filesize($filepath));
$response->setHeader('Content-Type', $mimeType);
$response->sendHeaders();
$handle = fopen($filepath, 'r');
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
echo $buffer;
}
if (!feof($handle)) {
throw new Exception("Error: unexpected fgets() fail.");
}
fclose($handle);
}
}
示例2: sendHeaders
/**
* Fixes CGI only one Status header allowed bug
*
* @link http://bugs.php.net/bug.php?id=36705
*
* @return Mage_Core_Controller_Response_Http
*/
public function sendHeaders()
{
if (!$this->canSendHeaders()) {
Mage::log('HEADERS ALREADY SENT: ' . mageDebugBacktrace(true, true, true));
return $this;
}
if (substr(php_sapi_name(), 0, 3) == 'cgi') {
$statusSent = false;
foreach ($this->_headersRaw as $i => $header) {
if (stripos($header, 'status:') === 0) {
if ($statusSent) {
unset($this->_headersRaw[$i]);
} else {
$statusSent = true;
}
}
}
foreach ($this->_headers as $i => $header) {
if (strcasecmp($header['name'], 'status') === 0) {
if ($statusSent) {
unset($this->_headers[$i]);
} else {
$statusSent = true;
}
}
}
}
return parent::sendHeaders();
}
示例3: sendHeaders
/**
* Sends all headers
*
* @return Enlight_Controller_Response_ResponseHttp
*/
public function sendHeaders()
{
if (count($this->_cookies)) {
$this->canSendHeaders(true);
foreach ($this->_cookies as $name => $cookie) {
setcookie($name, $cookie['value'], $cookie['expire'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']);
}
}
return parent::sendHeaders();
}
示例4: _outputLinkRedirect
/**
* Intercept a request for a link redirect
*
* @param string|bool $error If non-false, an error that occurred when validating the request
*/
protected function _outputLinkRedirect($error)
{
if ($error === 'invalid_url') {
header('Content-Type: text/html; utf-8', true, 500);
die('Invalid URL');
}
if (empty(XenForo_Application::getOptions()->imageLinkProxy['links'])) {
$error = 'disabled';
}
if (!$error) {
/* @var $proxyModel XenForo_Model_LinkProxy */
$proxyModel = XenForo_Model::create('XenForo_Model_LinkProxy');
$linkId = $proxyModel->logVisit($this->_url);
if ($linkId && !empty(XenForo_Application::getOptions()->imageLinkProxyReferrer['enabled']) && $this->_referrer) {
$proxyModel->logLinkReferrer($linkId, $this->_referrer);
}
if ($this->_json) {
header('Content-type: application/json; charset=UTF-8');
echo json_encode(array('logged' => true));
exit;
}
// this used to redirect, but we don't take this approach any longer, so we display an intersitial
}
$request = new Zend_Controller_Request_Http();
XenForo_Session::startPublicSession($request);
$this->_dependencies->preRenderView();
if (!preg_match('#^https?://#i', $this->_url)) {
throw new Exception('Unsafe proxy URL: ' . $this->_url);
}
$printable = urldecode($this->_url);
if (!preg_match('/./u', $printable)) {
$printable = $this->_url;
}
$renderer = new XenForo_ViewRenderer_HtmlPublic($this->_dependencies, $this->_response, $request);
$contents = $renderer->createTemplateObject('link_redirect', array('url' => $this->_url, 'printable' => $printable, 'parts' => parse_url($this->_url)));
$containerParams = $this->_dependencies->getEffectiveContainerParams(array(), $request);
$output = $renderer->renderContainer($contents, $containerParams);
$extraHeaders = XenForo_Application::gzipContentIfSupported($output);
foreach ($extraHeaders as $extraHeader) {
$this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]);
}
$this->_response->setHeader('X-Proxy-Error', $error);
$this->_response->sendHeaders();
echo $output;
}
示例5: send
/**
* @param array $options
*
* @throws Exception
*/
public function send($options = array())
{
if (is_string($options)) {
$options = array('filepath' => $options);
} elseif (!is_array($options)) {
$options = array();
}
$filepath = isset($options['filepath']) ? $options['filepath'] : '';
if (!is_file($filepath) || !is_readable($filepath)) {
throw new Exception("File '{$filepath}' does not exists.");
}
$response = new Zend_Controller_Response_Http();
$response->setHeader('Content-Length', filesize($filepath));
$response->setHeader('Content-Type', $this->_detectMimeType(array('name' => $filepath)));
if (array_key_exists('headers', $options) && is_array($options['headers'])) {
foreach ($options['headers'] as $header => $value) {
$response->setHeader($header, $value);
}
}
$response->setHeader('ETag', md5_file($filepath));
$response->sendHeaders();
readfile($filepath);
}
示例6: sendHeaders
/**
* Fixes CGI only one Status header allowed bug
*
* @link http://bugs.php.net/bug.php?id=36705
*
* @return Mage_Core_Controller_Response_Http
*/
public function sendHeaders()
{
// Only check if we can send headers if we have headers to send
if (count($this->_headersRaw) || count($this->_headers) || 200 != $this->_httpResponseCode) {
if (!$this->canSendHeaders()) {
headers_sent($file, $line);
Mage::log("HEADERS ALREADY SENT: {$file}:{$line}");
return $this;
}
} elseif (200 == $this->_httpResponseCode) {
// Haven't changed the response code, and we have no headers
return $this;
}
if (substr(php_sapi_name(), 0, 3) == 'cgi') {
$statusSent = false;
foreach ($this->_headersRaw as $i => $header) {
if (stripos($header, 'status:') === 0) {
if ($statusSent) {
unset($this->_headersRaw[$i]);
} else {
$statusSent = true;
}
}
}
foreach ($this->_headers as $i => $header) {
if (strcasecmp($header['name'], 'status') === 0) {
if ($statusSent) {
unset($this->_headers[$i]);
} else {
$statusSent = true;
}
}
}
}
return parent::sendHeaders();
}
示例7: run
/**
* Runs the request, handling from routing straight through to response output.
* Primary method to be used by the external API.
*
* @return string|null Returns a string if {@link $_sendResponse} is false
*/
public function run()
{
ob_start();
XenForo_Application::set('fc', $this);
$this->setup();
$this->setRequestPaths();
$showDebugOutput = $this->showDebugOutput();
$this->_dependencies->preLoadData();
XenForo_CodeEvent::fire('front_controller_pre_route', array($this));
$routeMatch = $this->route();
XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch));
$controllerResponse = $this->dispatch($routeMatch);
if (!$controllerResponse) {
XenForo_Error::noControllerResponse($routeMatch, $this->_request);
exit;
}
$viewRenderer = $this->_getViewRenderer($routeMatch->getResponseType());
if (!$viewRenderer) {
// note: should only happen if there's an error getting the default renderer, which should never happen :)
XenForo_Error::noViewRenderer($this->_request);
exit;
}
$containerParams = array('majorSection' => $routeMatch->getMajorSection(), 'minorSection' => $routeMatch->getMinorSection());
XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams));
$content = $this->renderView($controllerResponse, $viewRenderer, $containerParams);
if ($showDebugOutput) {
$content = $this->renderDebugOutput($content);
}
$bufferedContents = ob_get_contents();
ob_end_clean();
if ($bufferedContents !== '' && is_string($content)) {
if (preg_match('#<body[^>]*>#sU', $content, $match)) {
$content = str_replace($match[0], $match[0] . $bufferedContents, $content);
} else {
$content = $bufferedContents . $content;
}
}
XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content));
if ($this->_sendResponse) {
$headers = $this->_response->getHeaders();
$isText = false;
foreach ($headers as $header) {
if ($header['name'] == 'Content-Type') {
if (strpos($header['value'], 'text/') === 0) {
$isText = true;
}
break;
}
}
if ($isText && is_string($content) && $content) {
$extraHeaders = XenForo_Application::gzipContentIfSupported($content);
foreach ($extraHeaders as $extraHeader) {
$this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]);
}
}
if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) {
if ($this->_response->getHttpResponseCode() >= 400 && strpos($this->_request->getServer('HTTP_USER_AGENT', ''), 'IEMobile') !== false) {
// Windows mobile bug - 400+ errors cause the standard browser error
// to be output if a content length is sent. ...Err, what?
} else {
$this->_response->setHeader('Content-Length', strlen($content), true);
}
}
$this->_response->sendHeaders();
if ($content instanceof XenForo_FileOutput) {
$content->output();
} else {
echo $content;
}
} else {
return $content;
}
}
示例8: sendHeaders
/**
* Send all headers
*
* Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code}
* has been specified, it is sent with the first header.
*
* @return Zym_Controller_Response_Http
*/
public function sendHeaders()
{
// Only check if we can send headers if we have headers to send
if (count($this->_cookies)) {
$this->canSendHeaders(true);
}
// Send cookies
foreach ($this->_cookies as $cookie) {
setrawcookie($cookie['name'], $cookie['value'], $cookie['expire'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']);
}
return parent::sendHeaders();
}
示例9: run
/**
* Runs the request, handling from routing straight through to response output.
* Primary method to be used by the external API.
*
* @return string|null Returns a string if {@link $_sendResponse} is false
*/
public function run($innerContent = "", $newParams = array())
{
ob_start();
$this->setup();
$this->setRequestPaths();
$showDebugOutput = $this->showDebugOutput();
$this->_dependencies->preLoadData();
XenForo_CodeEvent::fire('front_controller_pre_route', array($this));
$routeMatch = $this->route();
XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch));
$controllerResponse = $this->dispatch($routeMatch);
if (!$controllerResponse) {
XenForo_Error::noControllerResponse($routeMatch, $this->_request);
exit;
}
$viewRenderer = $this->_getViewRenderer($routeMatch->getResponseType());
if (!$viewRenderer) {
// note: should only happen if there's an error getting the default renderer, which should never happen :)
XenForo_Error::noViewRenderer($this->_request);
exit;
}
$containerParams = array('majorSection' => $routeMatch->getMajorSection(), 'minorSection' => $routeMatch->getMinorSection());
XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams));
$content = $this->renderView($controllerResponse, $viewRenderer, $containerParams, $innerContent, $newParams);
if ($showDebugOutput) {
$content = $this->renderDebugOutput($content);
}
$bufferedContents = ob_get_contents();
ob_end_clean();
if ($bufferedContents !== '') {
$content = $bufferedContents . $content;
}
XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content));
if ($this->_sendResponse) {
$headers = $this->_response->getHeaders();
$isText = false;
foreach ($headers as $header) {
if ($header['name'] == 'Content-Type') {
if (strpos($header['value'], 'text/') === 0) {
$isText = true;
}
break;
}
}
if ($isText && is_string($content) && $content) {
$extraHeaders = XenForo_Application::gzipContentIfSupported($content);
foreach ($extraHeaders as $extraHeader) {
$this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]);
}
}
if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) {
$this->_response->setHeader('Content-Length', strlen($content), true);
}
$this->_response->sendHeaders();
if ($content instanceof XenForo_FileOutput) {
$content->output();
} else {
//$uncompressed = gzuncompress($content);
//echo $uncompressed;
echo $content;
}
} else {
return $content;
}
}
示例10: sendHeaders
/**
* Fixes CGI only one Status header allowed bug
*
* @link http://bugs.php.net/bug.php?id=36705
*
* @return Mage_Core_Controller_Response_Http
*/
public function sendHeaders()
{
if (!$this->canSendHeaders()) {
Mage::log('HEADERS ALREADY SENT: ' . mageDebugBacktrace(true, true, true));
return $this;
}
if (substr(php_sapi_name(), 0, 3) == 'fpm') {
$statusSent = FALSE;
$contentSent = FALSE;
foreach ($this->_headersRaw as $i => $header) {
if (stripos($header, 'status:') === 0 || stripos($header, 'http/1.1') === 0) {
if ($statusSent) {
unset($this->_headersRaw[$i]);
} else {
$statusSent = true;
}
}
if (stripos($header, 'content-type') === 0) {
if ($contentSent) {
unset($this->_headersRaw[$i]);
} else {
$contentSent = true;
}
}
}
foreach ($this->_headers as $i => $header) {
if (strcasecmp($header['name'], 'status') === 0 || strcasecmp($header['name'], 'Http/1.1') === 0) {
if ($statusSent) {
unset($this->_headers[$i]);
} else {
$statusSent = true;
}
}
if (strcasecmp($header['name'], 'content-type') === 0) {
if ($contentSent || substr($header['value'], 0, 9) == 'text/html') {
unset($this->_headers[$i]);
} else {
$contentSent = true;
}
}
}
}
parent::sendHeaders();
}
示例11: dispatch
/**
* Pretend to dispatch an HTTP request to a controller/action.
*
* @param Zend_Controller_Request_Abstract|null $request
* @param Zend_Controller_Response_Abstract|null $response
* @return Zend_Controller_Response_Abstract|void Response object
*/
public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
{
$response = new Zend_Controller_Response_Http();
$response->setBody($request->getControllerName() . ':' . $request->getActionName());
if ($this->returnResponse()) {
return $response;
}
$response->sendHeaders();
$response->outputBody();
}
示例12: sendHeaders
/**
* Sends all headers
*
* @return Enlight_Controller_Response_ResponseHttp
*/
public function sendHeaders()
{
$this->sendCookies();
return parent::sendHeaders();
}
示例13: sendHeaders
/**
* Fixes CGI only one Status header allowed bug
* 17.10.2014 added Bugfix (2nd link)
*
* @link http://bugs.php.net/bug.php?id=36705
* @link http://blog.swiftcore.com/2012/07/magento-duplicate-header-content-type-fastcgi-comm-with-server-xxxxxxx-aborted-error-parsing-headers.html
*
* @return Mage_Core_Controller_Response_Http
*/
public function sendHeaders()
{
if (!$this->canSendHeaders()) {
Mage::log('HEADERS ALREADY SENT: ' . mageDebugBacktrace(true, true, true));
return $this;
}
if (in_array(substr(php_sapi_name(), 0, 3), array('cgi', 'fpm'))) {
// remove duplicate headers
$remove = array('status', 'content-type');
// already sent headers
$sent = array();
foreach (headers_list() as $header) {
// parse name
if (!($pos = strpos($header, ':'))) {
continue;
}
$sent[strtolower(substr($header, 0, $pos))] = true;
}
// raw headers
$headersRaw = array();
foreach ($this->_headersRaw as $i => $header) {
// parse name
if (!($pos = strpos($header, ':'))) {
continue;
}
$name = strtolower(substr($header, 0, $pos));
if (in_array($name, $remove)) {
// check sent headers
// FG Addition: Check if array key exists
if (array_key_exists($name, $sent) && $sent[$name]) {
unset($this->_headersRaw[$i]);
continue;
}
// check header
if (!is_null($existing = $headers[$name])) {
$this->_headersRaw[$existing] = $header;
unset($this->_headersRaw[$i]);
} else {
$headersRaw[$name] = $i;
}
}
}
// object headers
$headers = array();
foreach ($this->_headers as $i => $header) {
$name = strtolower($header['name']);
if (in_array($name, $remove)) {
// check sent headers
// FG Addition: Check if array key exists
if (array_key_exists($name, $sent) && $sent[$name]) {
unset($this->_headers[$i]);
continue;
}
// check header
// FG Addition: Check if array key exists
if (array_key_exists($name, $headers) && !is_null($existing = $headers[$name])) {
$this->_headers[$existing] = $header;
unset($this->_headers[$i]);
} else {
$headers[$name] = $i;
}
// check raw headers
// FG Addition: Check if array key exists
if (array_key_exists($name, $headersRaw) && !is_null($existing = $headersRaw[$name])) {
unset($this->_headersRaw[$existing]);
}
}
}
}
return parent::sendHeaders();
}