From 8e6fb7e9cfbd7af8b24b933be2bbad3b6aec7e1d Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 22 Mar 2018 03:23:15 +0900 Subject: [PATCH] =?UTF-8?q?returnJson=20=EB=8F=99=EC=9E=91=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- f_func/func.php | 27 +++++++++------------------ twe/j_build_conf.php | 18 ++++++++++++------ twe/lib.php | 16 +++++++++++----- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/f_func/func.php b/f_func/func.php index 7e31a0a3..a96f4568 100644 --- a/f_func/func.php +++ b/f_func/func.php @@ -3,22 +3,16 @@ require(__dir__.'/../vendor/autoload.php'); function SetHeaderNoCache(){ if(!headers_sent()) { - header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1. - header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); + header('Expires: Wed, 01 Jan 2014 00:00:00 GMT'); + header('Cache-Control: no-store, no-cache, must-revalidate'); + header('Cache-Control: post-check=0, pre-check=0', FALSE); + header('Pragma: no-cache'); } } function CustomHeader() { - //FIXME: 왜 Contect-Type이 text/html로 고정이지?! - if(!headers_sent()) { - header('Cache-Control: no-cache'); - header('Pragma: no-cache'); -// header('Cache-Control: public'); -// header('Pragma: public'); -// header('Content-Type: text/html; charset=utf-8'); - } -//define(CURPATH, 'f_async'); -//define(FILE, substr(strrchr(__FILE__, "\\"), 1)); + //xxx: CustomHeader를 제거하기 전까진 유지 + SetHeaderNoCache(); } function getmicrotime() { @@ -124,14 +118,11 @@ function delExpiredInDir($dir, $t) { function returnJson($value, $noCache = true, $pretty = false, $die = true){ - header('Content-Type: application/json'); - if($noCache){ - header('Expires: Wed, 01 Jan 2014 00:00:00 GMT'); - header('Cache-Control: no-store, no-cache, must-revalidate'); - header('Cache-Control: post-check=0, pre-check=0', FALSE); - header('Pragma: no-cache'); + SetHeaderNoCache(); } + + header('Content-Type: application/json'); if($pretty){ $flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; diff --git a/twe/j_build_conf.php b/twe/j_build_conf.php index 227f9487..ca7d8d15 100644 --- a/twe/j_build_conf.php +++ b/twe/j_build_conf.php @@ -9,6 +9,15 @@ use utilphp\util as util; * 이 파일만 예외적으로 lib.php, func.php를 참조하지 않고 독자적으로 동작함. */ +function SetHeaderNoCache(){ + if(!headers_sent()) { + header('Expires: Wed, 01 Jan 2014 00:00:00 GMT'); + header('Cache-Control: no-store, no-cache, must-revalidate'); + header('Cache-Control: post-check=0, pre-check=0', FALSE); + header('Pragma: no-cache'); + } +} + function parseJsonPost(){ // http://thisinterestsme.com/receiving-json-post-data-via-php/ // http://thisinterestsme.com/php-json-error-handling/ @@ -68,14 +77,11 @@ function parseJsonPost(){ } function returnJson($value, $noCache = true, $pretty = false, $die = true){ - header('Content-Type: application/json'); - if($noCache){ - header('Expires: Sun, 01 Jan 2014 00:00:00 GMT'); - header('Cache-Control: no-store, no-cache, must-revalidate'); - header('Cache-Control: post-check=0, pre-check=0', FALSE); - header('Pragma: no-cache'); + SetHeaderNoCache(); } + + header('Content-Type: application/json'); if($pretty){ $flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; diff --git a/twe/lib.php b/twe/lib.php index 32b79db6..8fb209a2 100644 --- a/twe/lib.php +++ b/twe/lib.php @@ -132,15 +132,21 @@ function Error($message, $url="") { exit; } -function returnJson($value, $noCache = true, $pretty = false, $die = true){ - header('Content-Type: application/json'); - - if($noCache){ - header('Expires: Sun, 01 Jan 2014 00:00:00 GMT'); +function SetHeaderNoCache(){ + if(!headers_sent()) { + header('Expires: Wed, 01 Jan 2014 00:00:00 GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', FALSE); header('Pragma: no-cache'); } +} + +function returnJson($value, $noCache = true, $pretty = false, $die = true){ + if($noCache){ + SetHeaderNoCache(); + } + + header('Content-Type: application/json'); if($pretty){ $flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;