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


PHP http_response_code函数代码示例

本文整理汇总了PHP中http_response_code函数的典型用法代码示例。如果您正苦于以下问题:PHP http_response_code函数的具体用法?PHP http_response_code怎么用?PHP http_response_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: sendHeaders

 /**
  *
  */
 protected function sendHeaders()
 {
     http_response_code($this->httpResponseCode);
     foreach ($this->headers as $name => $value) {
         header($name . ': ' . $value);
     }
 }
开发者ID:freyr,项目名称:envelope,代码行数:10,代码来源:Response.php

示例2: get

 /**
  * Convert request to data result
  *
  * @access public
  * @fixme  Authentication / request validation
  * @return void
  */
 public function get($forecast = false, $data = false)
 {
     $validRequest = $this->_validateRequest() !== False;
     $validAuth = $this->_validateAuth() !== False;
     $post = $data !== false ? $data : $this->input->post();
     $post["download"] = false;
     if (isset($post["region"])) {
         $post["multiple"] = true;
     } else {
         $post["multiple"] = false;
     }
     if ($validRequest && $validAuth) {
         $source = new Source($post);
         $res = $source->get($this->_user);
         if ($forecast != false) {
             if ($this->_user) {
                 $result = $source->gatherForecast($this->_user);
                 if (isset($result[0])) {
                     array_push($res, $result[0]);
                 }
             }
         }
         echo json_encode($res);
     } else {
         http_response_code(400);
         echo json_encode(["message" => $this->_message]);
     }
     exit;
 }
开发者ID:kukua,项目名称:kukua-dashboard,代码行数:36,代码来源:Sensordata.php

示例3: input

 public function input()
 {
     if ($this->input === NULL) {
         $in = file_get_contents("php://input");
         if ($in != "" && $in != NULL) {
             $this->input = json_decode($in, true);
             if (json_last_error() != JSON_ERROR_NONE) {
                 // we have to do a raw write here...
                 http_response_code(400);
                 if (config('app.debug') === true) {
                     \Log::debug("Invalid JSON in this request: " . $in);
                 }
                 echo json_encode(["message" => "Error: Malformed JSON"]);
                 exit;
             }
             if (isset($this->input['payload']) && !empty($this->input['payload'])) {
                 $this->payload = $this->input['payload'];
             }
             if (isset($this->input['meta']) && !empty($this->input['meta'])) {
                 $this->meta = $this->input['meta'];
             }
         } else {
             $this->input = "";
         }
     }
     return $this->input;
 }
开发者ID:Neo-Desktop,项目名称:wm-browser,代码行数:27,代码来源:BaseController.php

示例4: response_error

function response_error($msg)
{
    http_response_code(400);
    $response = (object) ['msg' => $msg];
    echo json_encode($response);
    exit(1);
}
开发者ID:madbob,项目名称:VoiceHub,代码行数:7,代码来源:vh.js.php

示例5: set_headers

 private function set_headers()
 {
     header("HTTP/1.1" . $this->_code . " " . http_response_code($this->get_status_message()));
     //http_response_code($this->get_status_message());
     header("Content-Type:" . $this->_content_type);
     $this->logger->write("INFO :", "_code......" . $this->_code . "get_status_message..." . $this->get_status_message() . "_content_type...." . $this->_content_type);
 }
开发者ID:Rajeshwar90,项目名称:Referralio,代码行数:7,代码来源:Rest.inc.php

示例6: dumpError

function dumpError($error)
{
    http_response_code(500);
    echoHtmlHead();
    echo "<h3 style=\"background-color:orangered;padding:10px;\">{$error}</h3>";
    exit(1);
}
开发者ID:asylgrp,项目名称:workbench,代码行数:7,代码来源:setup.php

示例7: OnLoadPageData

 public function OnLoadPageData()
 {
     require_once 'stoolball/competition-manager.class.php';
     $manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection());
     if ($this->season_id) {
         $manager->ReadById(null, array($this->season_id));
     } else {
         $manager->ReadById(array($this->competition_id));
     }
     $this->competition = $manager->GetFirst();
     $this->season = $this->competition->GetWorkingSeason();
     unset($manager);
     # If the competition was requested, redirect to the current season
     if ($this->competition_id) {
         http_response_code(303);
         header("Location: " . $this->season->GetMapUrl());
         return;
     }
     $this->has_map = count($this->season->GetTeams());
     # Get other seasons
     require_once 'stoolball/season-manager.class.php';
     $a_comp_ids = array($this->competition->GetId());
     $o_season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
     $o_season_manager->ReadByCompetitionId($a_comp_ids);
     $a_other_seasons = $o_season_manager->GetItems();
     $this->competition->SetSeasons(array());
     foreach ($a_other_seasons as $season) {
         if ($season->GetId() == $this->season->GetId()) {
             $this->competition->AddSeason($this->season, true);
         } else {
             $this->competition->AddSeason($season, false);
         }
     }
 }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:34,代码来源:map.php

示例8: create_topic

function create_topic($request)
{
    Authenticator::assert_manager_or_professor($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale']);
    try {
        $raw_input = $request->getBody();
        $content_type = explode(';', $request->type)[0];
        if ($content_type !== 'application/json') {
            Util::output_errors_and_die('', 415);
        }
        $input_data = json_decode($raw_input, true);
        if (empty($input_data)) {
            Util::output_errors_and_die('', 400);
        }
        $model = new Model();
        if (!isset($input_data['name'])) {
            $input_data['name'] = '';
        }
        $topic_id = $model->create_topic($input_data['name']);
        if ($topic_id) {
            http_response_code(201);
            header('Content-Type: text/plain');
            echo '/topics/' . $topic_id;
            die;
        } else {
            Util::output_errors_and_die('', 400);
        }
    } catch (ConflictException $e) {
        Util::output_errors_and_die($e->getMessage(), 409);
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:35,代码来源:create_topic.php

示例9: sendHeaders

 /**
  * Sent HTTP headers and HTTP response code.
  */
 protected function sendHeaders()
 {
     http_response_code($this->status);
     foreach ($this->headers as $name => $value) {
         header("{$name}: {$value}");
     }
 }
开发者ID:gbv,项目名称:jskos-php,代码行数:10,代码来源:Response.php

示例10: throw400

 static function throw400($msg)
 {
     http_response_code(400);
     header('Content-Type: text/plain');
     echo $msg;
     exit;
 }
开发者ID:kba,项目名称:rssscrpr,代码行数:7,代码来源:Utils.php

示例11: combineChunks

 public function combineChunks($uploadDirectory, $name = null)
 {
     $uuid = $_POST['qquuid'];
     if ($name === null) {
         $name = $this->getName();
     }
     $targetFolder = $this->chunksFolder . DIRECTORY_SEPARATOR . $uuid;
     $totalParts = isset($_REQUEST['qqtotalparts']) ? (int) $_REQUEST['qqtotalparts'] : 1;
     $targetPath = join(DIRECTORY_SEPARATOR, array($uploadDirectory, $uuid, $name));
     $this->uploadName = $name;
     if (!file_exists($targetPath)) {
         mkdir(dirname($targetPath), 0777, true);
     }
     $target = fopen($targetPath, 'wb');
     for ($i = 0; $i < $totalParts; $i++) {
         $chunk = fopen($targetFolder . DIRECTORY_SEPARATOR . $i, "rb");
         stream_copy_to_stream($chunk, $target);
         fclose($chunk);
     }
     // Success
     fclose($target);
     for ($i = 0; $i < $totalParts; $i++) {
         unlink($targetFolder . DIRECTORY_SEPARATOR . $i);
     }
     rmdir($targetFolder);
     if (!is_null($this->sizeLimit) && filesize($targetPath) > $this->sizeLimit) {
         unlink($targetPath);
         http_response_code(413);
         return array("success" => false, "uuid" => $uuid, "preventRetry" => true);
     }
     return array("success" => true, "uuid" => $uuid);
 }
开发者ID:fineuploader,项目名称:php-traditional-server,代码行数:32,代码来源:handler.php

示例12: modAction

 /**
  * This is a general purpose hook, allowing modules to respond to routes
  * of the form module.php?mod=FOO&mod_action=BAR
  *
  * @param string $mod_action
  */
 public function modAction($mod_action)
 {
     switch ($mod_action) {
         case 'admin_config':
             $this->config();
             break;
         case 'admin_delete':
             $this->delete();
             $this->config();
             break;
         case 'admin_edit':
             $this->edit();
             break;
         case 'admin_movedown':
             $this->movedown();
             $this->config();
             break;
         case 'admin_moveup':
             $this->moveup();
             $this->config();
             break;
         case 'show':
             $this->show();
             break;
         default:
             http_response_code(404);
     }
 }
开发者ID:tunandras,项目名称:webtrees,代码行数:34,代码来源:FrequentlyAskedQuestionsModule.php

示例13: sendErrorAndDie

function sendErrorAndDie($code, $msg)
{
    error_log($msg);
    include 'error.php';
    http_response_code($code);
    die;
}
开发者ID:pinkiesky,项目名称:aoim-web,代码行数:7,代码来源:message.php

示例14: test_auto_marking_sc

function test_auto_marking_sc($request)
{
    Authenticator::assert_manager_or_professor($request->cookies['authToken']);
    $msg = new Messages($GLOBALS['locale'], '/new-question/errors');
    try {
        $model = new Model();
        $raw_input = $request->getBody();
        $content_type = explode(';', $request->type)[0];
        if ($content_type !== 'application/json') {
            Util::output_errors_and_die($msg->_('invalid-format'), 415);
        }
        $input_data = json_decode($raw_input, true);
        if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['source-code']) || !is_string($input_data['source-code'])) {
            Util::output_errors_and_die($msg->_('invalid-format'), 400);
        }
        $extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
        $qd = $input_data['question'];
        set_empty_if_undefined($qd['type']);
        if ($qd['type'] != 'source-code') {
            Util::output_errors_and_die('', 400);
        }
        $q = new QuestionSC($qd, Question::FROM_USER, $extra);
        $q->mark_automatically(array('source-code' => $input_data['source-code']), $log, $result);
        http_response_code(200);
        header('Content-Type: application/json');
        echo my_json_encode($result);
    } catch (DatabaseException $e) {
        Util::output_errors_and_die($e->getMessage(), 503);
    } catch (Exception $e) {
        Util::output_errors_and_die($e->getMessage(), 400);
    }
}
开发者ID:OrgAindaSemTitulo,项目名称:Sistema,代码行数:32,代码来源:test_auto_marking_sc.php

示例15: initDashboard

function initDashboard()
{
    include_once ABSPATH . "/php/CDBConn.php";
    include_once ABSPATH . "/php/hostconfig.php";
    $conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
    if (!$conn->connect_no_localhost()) {
        http_response_code(503);
        exit;
    }
    $cur_login = $_SESSION['g_username'];
    $get_hostel_id_sql = "SELECT hostel_id FROM users WHERE login = '{$cur_login}'";
    $conn->run_query($get_hostel_id_sql);
    $line = $conn->fetch_array();
    // We almost now from which hostel is user
    $hostel_id = $line['hostel_id'];
    // in case if hostel id is not set, it's an indicator that hostel  definetely has not been configured yet.
    if ($hostel_id === NULL) {
        header("Location: /configure/index.php");
        exit;
    }
    $get_is_configured_sql = "SELECT is_configured FROM hostels WHERE id = {$hostel_id}";
    $conn->run_query($get_is_configured_sql);
    $line = $conn->fetch_array();
    $is_configured = $line['is_configured'];
    // This is the case when user almost configured not
    if ($is_configured === 'f') {
        header("Location: /configure/index.php");
        // exit();
    }
    $conn->close();
}
开发者ID:nuriyevn,项目名称:jetpms,代码行数:31,代码来源:initDashboard.php


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