当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpUtility::setResponseCode方法代码示例

本文整理汇总了PHP中TYPO3\CMS\Core\Utility\HttpUtility::setResponseCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpUtility::setResponseCode方法的具体用法?PHP HttpUtility::setResponseCode怎么用?PHP HttpUtility::setResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TYPO3\CMS\Core\Utility\HttpUtility的用法示例。


在下文中一共展示了HttpUtility::setResponseCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pageNotFound


//.........这里部分代码省略.........
         // iterate through multiple 404 page definitions
     }
     // if 404 page(s) has been set.
     // Get 401 page uid
     $error401Uid = 0;
     if (isset($extensionConfiguration['error401Uid'])) {
         $error401Uids = GeneralUtility::trimExplode(',', $extensionConfiguration['error401Uid']);
         if (count($error401Uids) === 1 && substr_count($error401Uids[0], ':') === 0) {
             $error401Uid = $error401Uids[0];
             // Parse 401 uids on a per-host basis
         } else {
             // Iterate through all defined hosts/error page uids
             foreach ($error401Uids as $errorPageHostAndUid) {
                 $errorPageHostAndUid = GeneralUtility::trimExplode(':', $errorPageHostAndUid);
                 // Check correct definition format ([host name or part thereof]:[errorpage uid],...)
                 if (count($errorPageHostAndUid) !== 2) {
                     continue;
                     // Host pattern found in current error page definition.
                 } elseif (substr_count($host, strtolower($errorPageHostAndUid[0])) > 0) {
                     $error401Uid = $errorPageHostAndUid[1];
                     break;
                 }
             }
         }
         // iterate through multiple 404 page definitions
     }
     // if 401 page(s) has been set.
     // Get sys language uid
     $sysLanguageUid = 0;
     // ... via GET parameter
     if (GeneralUtility::_GET($languageParameter)) {
         $sysLanguageUid = GeneralUtility::_GET($languageParameter);
         // ... via realurl configuration
     } elseif (ExtensionManagementUtility::isLoaded('realurl')) {
         $realUrlConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'];
         if (isset($realUrlConf[$host])) {
             $realUrlDomainConf = $realUrlConf[$host];
         } else {
             $realUrlDomainConf = $realUrlConf['_DEFAULT'];
         }
         // Iterate through preVars to find language preVar position in url and value
         foreach ($realUrlDomainConf['preVars'] as $preVarPosition => $preVarConf) {
             if ($preVarConf['GETvar'] == $languageParameter) {
                 // Get preVar value from URL
                 $uriParts = GeneralUtility::trimExplode('/', GeneralUtility::getIndpEnv('REQUEST_URI'), true);
                 $language = $uriParts[$preVarPosition];
                 if (isset($preVarConf['valueMap'][$language])) {
                     $sysLanguageUid = intval($preVarConf['valueMap'][$language]);
                 }
                 break;
             }
         }
     }
     // if realurl is installed
     // Check failure reason
     // Always use FIRST failure reason as it may have multiple reasons
     // combined (such as hidden and/or limited to fe_usergroups)
     $isAuthorizationAccessFailure = false;
     $firstFailureReason = array_keys($params['pageAccessFailureReasons'])[0];
     if ($firstFailureReason == 'fe_group') {
         if (is_array($params['pageAccessFailureReasons']['fe_group']) && count($params['pageAccessFailureReasons']['fe_group'])) {
             $isAuthorizationAccessFailure = true;
         }
     }
     // Generate redirect link and status
     $redirectLink = NULL;
     $isAuthorizationAccessFailure = false;
     // 401
     if ($isAuthorizationAccessFailure && $error401Uid) {
         $redirectLink = $currentURLParsed['scheme'] . '://' . $host . '/index.php?id=' . $error401Uid;
         $headerStatus = HttpUtility::HTTP_STATUS_401;
         // 404
     } elseif ($error404Uid) {
         $redirectLink = $currentURLParsed['scheme'] . '://' . $host . '/index.php?id=' . $error404Uid;
         $headerStatus = HttpUtility::HTTP_STATUS_404;
     }
     // Perform redirect
     $redirectLoops = intval(GeneralUtility::_GET('redirectloops'));
     $redirectLoops++;
     if ($redirectLink && $redirectLoops <= $maxNumberOfRedirects) {
         if ($sysLanguageUid) {
             $redirectLink .= '&' . $languageParameter . '=' . $sysLanguageUid;
         }
         $redirectLink .= '&redirectloops=' . $redirectLoops;
         HttpUtility::setResponseCode($headerStatus);
         $urlContent = GeneralUtility::getUrl($redirectLink);
         $urlContent = trim($urlContent);
         print $urlContent;
     }
     if (!empty($urlContent)) {
         die;
     }
     // Not redirected so far? Maximum number of redirects reached? Throw raw 404 as fallback.
     HttpUtility::setResponseCode(HttpUtility::HTTP_STATUS_404);
     $title = 'Page Not Found';
     $message = $params['reasonText'] . '.<br /><br />PageNotFoundHandler could not handle the request. Either the maximum number of ' . 'redirects (' . $maxNumberOfRedirects . ') have been reached or no target page has been configured. <br /><br />' . '<br />URL: "' . $params['currentUrl'] . '"';
     $messagePage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\ErrorpageMessage::class, $message, $title);
     $messagePage->output();
     die;
 }
开发者ID:martinpfister,项目名称:manuel,代码行数:101,代码来源:PageNotFoundHandler.php

示例2: render

 /**
  * Override the status code
  *
  * @param string $status
  * @return void
  */
 public function render($status = '404')
 {
     \TYPO3\CMS\Core\Utility\HttpUtility::setResponseCode($this->getResponseCode($status));
 }
开发者ID:koninklijke-collective,项目名称:koning_library,代码行数:10,代码来源:HeaderStatusViewHelper.php


注:本文中的TYPO3\CMS\Core\Utility\HttpUtility::setResponseCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。