note 81194 modified in function.filemtime by danbrown
| From: | danbrown@php.net | Date: | Fri, 19 Dec 2008 19:41:44 +0000 |
| Subject: | note 81194 modified in function.filemtime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148370@lists.php.net to get a copy of this message | ||
This is a very handy function for dealing with browser caching. For example, say you have a
stylesheet and you want to make sure everyone has the most recent version. You could rename it every
time you edit it, but that would be a pain in the ass. Instead, you can do this:
<?php
echo '<link rel="stylesheet" type="text/css" href="style.css?'
. filemtime('style.css') . '" />';
?>
Sample output:
<link rel="stylesheet" type="text/css" href="style.css?1203291283"
/>
By appending a GET value (the UNIX timestamp) to the stylesheet URL, you make the browser think the
stylesheet is dynamic, so it'll reload the stylesheet every time the modification date changes.
--was--
This is a very handy function for dealing with browser caching. For example, say you have a
stylesheet and you want to make sure everyone has the most recent version. You could rename it every
time you edit it, but that would be a pain in the ass. Instead, you can do this:
<?
echo '
<link rel="stylesheet" type="text/css" href="style.css?' .
filemtime('style.css') . '" />';
?>
Sample output:
<link rel="stylesheet" type="text/css" href="style.css?1203291283"
/>
By appending a GET value (the UNIX timestamp) to the stylesheet URL, you make the browser think the
stylesheet is dynamic, so it'll reload the stylesheet every time the modification date changes.
http://php.net/manual/en/function.filemtime.php