本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例4: response_error
function response_error($msg)
{
http_response_code(400);
$response = (object) ['msg' => $msg];
echo json_encode($response);
exit(1);
}
示例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);
}
示例6: dumpError
function dumpError($error)
{
http_response_code(500);
echoHtmlHead();
echo "<h3 style=\"background-color:orangered;padding:10px;\">{$error}</h3>";
exit(1);
}
示例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);
}
}
}
示例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);
}
}
示例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}");
}
}
示例10: throw400
static function throw400($msg)
{
http_response_code(400);
header('Content-Type: text/plain');
echo $msg;
exit;
}
示例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);
}
示例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);
}
}
示例13: sendErrorAndDie
function sendErrorAndDie($code, $msg)
{
error_log($msg);
include 'error.php';
http_response_code($code);
die;
}
示例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);
}
}
示例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();
}