diff options
author | Urban Müller | 2022-05-02 17:25:18 +0200 |
---|---|---|
committer | Urban Müller | 2022-05-02 17:25:18 +0200 |
commit | 439af54ba6b7a654ba6ad7a3b6b93cdaa2f077d0 (patch) | |
tree | d69d86e0ca3531c918f53a4cbe017cfc261daf72 /itjs.class | |
parent | 8c102f8d5428987dddc5f8b0cf9114789bd4a9b6 (diff) | |
download | itools-439af54ba6b7a654ba6ad7a3b6b93cdaa2f077d0.tar.gz itools-439af54ba6b7a654ba6ad7a3b6b93cdaa2f077d0.tar.bz2 itools-439af54ba6b7a654ba6ad7a3b6b93cdaa2f077d0.zip |
introduce ::json_headers, kill unused var
Diffstat (limited to 'itjs.class')
-rw-r--r-- | itjs.class | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -21,7 +21,6 @@ class itjs { -static $charset; /** * Send HTTP headers (content-type) to transmit javascript code @@ -31,13 +30,25 @@ static function send_headers($charset = null) if (!$charset) $charset = ini_get('default_charset') ?: 'iso-8859-1'; - self::$charset = $charset; - @header("Content-Type: application/x-javascript; charset=$charset"); @header('Expires: ' . gmdate('D, d M Y H:i:s', time()+10) . ' GMT'); # prevent broken data on IE reloads } /** + * Send HTTP headers (content-type) to send json + * $p['maxage'] Number of seconds the content is valid for without verification [30] + */ +static function json_headers($p = []) +{ + $p += ['charset' => ini_get('default_charset') ?: 'iso-8859-1', 'maxage' => 30]; + + @header("Content-Type: application/json; charset=" . $p['charset']); + if ($p['maxage']) + @header("Cache-Control: max-age=" . $p['maxage']); +} + + +/** * json_encode the result with options suitable for using as javascript source code * @param $values Array with values to be serialized * @return String with javascript code to be sent to client |