title: Setting up Expire Headers with PHP
body: <p>could anyone help me with setting up Expire Headers using PHP only,
  .htaccess is no good, because my host won't enable mod_expires on apache.</p>
  
  <p>So basically I'm looking for a way to do:</p>
  
  <pre><code>Expire Header
  &lt;FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$"&gt;
  ExpiresDefault "access plus 365 days"
  &lt;/FilesMatch&gt;
  </code></pre>
  
  <p>with php only.</p>
  
  <p>its also important to have different expire periods for different filetypes, so I tried using something like:</p>
  
  <pre><code>header ("content-type: image/jpg; charset: UTF-8");
  header ("cache-control: must-revalidate");
  $offset = 48 * 60 * 60;
  $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
  header ($expire);
  </code></pre>
  
  <p>for each type of files, but nothing happened.</p>
  
  <hr>
  
  <p>the headers after adding the PHP code, and taken from private session:</p>
  
  <pre><code>Response Headersview source
  Date    Mon, 25 Apr 2011 19:47:10 GMT
  Server  Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
  X-Powered-By    PHP/5.3.1
  P3P CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
  Expires Mon, 1 Jan 2001 00:00:00 GMT
  Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  Last-Modified   Mon, 25 Apr 2011 19:47:10 GMT
  Content-Encoding    gzip
  Pragma  no-cache
  Keep-Alive  timeout=5, max=100
  Connection  Keep-Alive
  Transfer-Encoding   chunked
  Content-Type    text/html; charset=utf-8
  Request Headersview source
  Host    localhost
  User-Agent  Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16 ( .NET CLR 3.5.30729) FirePHP/0.5
  Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language en-us,en;q=0.7,he;q=0.3
  Accept-Encoding gzip,deflate
  Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
  Keep-Alive  115
  Connection  keep-alive
  Referer http://localhost/-----------------
  Cookie  fboard_settings[current_view]=flat; style_cookie=null; phpbb3_4s1go_k=; phpbb3_4s1go_u=2; phpbb3_4s1go_sid=8a3835a63834e9851b0cde3e2f6cff63; jw_clean_pro_tpl=jw_clean_pro; acpSearchCookie[searchphrase]=any; acpSearchCookie[acpSearch]=%D7%97%D7%A4%D7%A9+...; acpSearchCookie[cid]=0; acpSearchCookie[field_city]=0; 14a2bb08766d6180968b7925b7902d70=bgd3h1uj5dctoevtdiaj1jtmg6; 3e2fd857422e2463a01f9631f718017a=nbdjbmjsn9ee8ng90ui816hec2
  x-insight   activate
  </code></pre>