3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php //get the last-modified-date of this very file $lastModified=filemtime($_SERVER['SCRIPT_FILENAME']); //get a unique hash of this file (etag) $etagFile = md5_file($_SERVER['SCRIPT_FILENAME']); //get the HTTP_IF_MODIFIED_SINCE header if set $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); //get the HTTP_IF_NONE_MATCH header if set (etag: unique file hash) $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"); header("Etag: $etagFile"); $ttc=60*60*24*8; header('Cache-Control: private; max-age='.$ttc); header('Expires: '.gmdate("D, d M Y H:i:s", time() + $ttc)); header("Pragma: cache"); //check if page has changed. If not, send 304 and exit if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader == $etagFile) { header("HTTP/1.1 304 Not Modified"); exit; } //your normal code echo "<!-- This page was last modified: ".date("d.m.Y H:i:s",$lastModified)." -->"; ?>
Output for 7.3.0rc4
<!-- This page was last modified: 06.11.2018 13:41:44 -->
Output for 7.3.0rc3
<!-- This page was last modified: 20.10.2018 05:19:37 -->
Output for 7.3.0beta1
<!-- This page was last modified: 10.08.2018 14:10:57 -->
Output for 7.3.0alpha1
<!-- This page was last modified: 18.06.2018 23:19:03 -->
Output for 7.2.6
<!-- This page was last modified: 17.06.2018 13:10:06 -->
Output for 7.2.0
<!-- This page was last modified: 30.11.2017 16:10:32 -->
Output for 7.1.20
<!-- This page was last modified: 12.08.2018 04:02:34 -->
Output for 7.1.10
<!-- This page was last modified: 21.10.2017 15:50:04 -->
Output for 7.1.7
<!-- This page was last modified: 16.07.2017 03:18:07 -->
Output for 7.1.6
<!-- This page was last modified: 28.06.2017 12:30:22 -->
Output for 7.1.5
<!-- This page was last modified: 03.07.2017 06:21:40 -->
Output for 7.1.0
<!-- This page was last modified: 04.12.2016 18:07:42 -->
Output for 7.0.20
<!-- This page was last modified: 30.06.2017 14:15:42 -->
Output for 7.0.14
<!-- This page was last modified: 10.12.2016 01:48:14 -->
Output for 5.2.3 - 5.6.25, 7.0.0 - 7.0.10
<!-- This page was last modified: 14.07.2014 06:13:46 -->
Output for 5.6.28
<!-- This page was last modified: 07.12.2016 13:16:42 -->
Output for 4.4.0 - 4.4.9, 5.0.5 - 5.2.2
Notice: Undefined index: SCRIPT_FILENAME in /in/fGY9e on line 3 Notice: Undefined index: SCRIPT_FILENAME in /in/fGY9e on line 5
Output for 4.3.2 - 4.3.11, 5.0.0 - 5.0.4
Notice: Undefined index: SCRIPT_FILENAME in /in/fGY9e on line 3 Notice: Undefined index: SCRIPT_FILENAME in /in/fGY9e on line 5 Warning: md5_file(): Unable to open file in /in/fGY9e on line 5
Output for 4.3.0 - 4.3.1
Notice: Undefined index: SCRIPT_FILENAME in /in/fGY9e on line 3 Warning: filemtime() [http://www.php.net/function.filemtime]: Stat failed for (errno=2 - No such file or directory) in /in/fGY9e on line 3 Notice: Undefined index: SCRIPT_FILENAME in /in/fGY9e on line 5 Warning: md5_file() [http://www.php.net/function.md5-file]: Unable to open file in /in/fGY9e on line 5