3v4l.org

run code in 300+ PHP versions simultaneously
<?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 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
<!-- This page was last modified: 16.12.2013 15:05:26 -->
Output for 5.2.3 - 5.2.17
<!-- This page was last modified: 14.07.2014 06:13:46 -->
Output for 4.4.0 - 4.4.9, 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 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

preferences:
201.17 ms | 402 KiB | 325 Q