[web-shared] master: Supports setting cache and http_response_code in header (#13)
| From: | Luffy via GitHub | Date: | Mon, 26 Oct 2026 13:59:39 +0000 |
| Subject: | [web-shared] master: Supports setting cache and http_response_code in header (#13) | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-34149@lists.php.net to get a copy of this message | ||
Author: Luffy (sy-records)
Committer: GitHub (web-flow)
Pusher: derickr
Date: 2026-10-26T13:59:35Z
Commit: https://github.com/php/web-shared/commit/019245748b459f98820f57ba09c6db0cdd971e04
Raw diff: https://github.com/php/web-shared/commit/019245748b459f98820f57ba09c6db0cdd971e04.diff
Supports setting cache and http_response_code in header (#13)
Changed paths:
M templates/header.inc
Diff:
diff --git a/templates/header.inc b/templates/header.inc
index df3a7e9..97506f7 100644
--- a/templates/header.inc
+++ b/templates/header.inc
@@ -20,6 +20,11 @@
* "hidden" => array(array("name" =>
"hidden-input-name", "value" => "hidden-input-value")),
* ); // Search box, if any
* $CURRENT_PAGE // The current page
+ * $CONFIG = array(
+ * "cache" => 1234567890, // optional, timestamp for Last
+ * "cache_control" => 3600, // optional, seconds for Cache-Control
+ * "http_response_code" => 404, // optional, HTTP response code
+ * );
*/
isset($TITLE) || $TITLE = "Hypertext Preprocessor";
isset($SUBDOMAIN) || $SUBDOMAIN = "";
@@ -29,8 +34,32 @@ isset($HEAD_RAND) || $HEAD_RAND = "";
isset($CSS) || $CSS = array();
isset($SEARCH) || $SEARCH = array();
isset($CURRENT_PAGE) || $CURRENT_PAGE = "";
+isset($CONFIG) || $CONFIG = array();
$ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ?
"//shared.php.net" : "/shared";
$current_time = time();
+
+if (isset($CONFIG["cache"])) {
+ if (is_numeric($CONFIG["cache"])) {
+ $timestamp = $CONFIG["cache"];
+ } else {
+ $timestamp = $current_time;
+ }
+ $tsstring = gmdate("D, d M Y H:i:s ", $timestamp) . "GMT";
+
+ if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) &&
$_SERVER["HTTP_IF_MODIFIED_SINCE"] == $tsstring) {
+ header("HTTP/1.1 304 Not Modified");
+ exit;
+ }
+ header("Last-Modified: " . $tsstring);
+}
+
+if (isset($CONFIG["cache_control"]) &&
is_numeric($CONFIG["cache_control"])) {
+ header("Cache-Control: public, max-age=" . (int) $CONFIG["cache_control"]);
+}
+
+if (isset($CONFIG['http_response_code'])) {
+ http_response_code($CONFIG['http_response_code']);
+}
?>
<!DOCTYPE html>
<html>