RFC 1123 dates in PHP

| date | PHP | rfc

While playing with REDbot I realised my last-modified headers (being sent by PHP) were not RFC 1123 complaint. A complaint date looks like Sun, 06 Nov 1994 08:49:37 GMT. There are two ways to generate such a date in PHP;

  1. if you have pecl_http >= 0.1.0, then

  2. or if you don’t want to use pecl

    gmdate('D, d M Y H:i:s', $timestamp).' GMT'
  3. or if you have PHP >5.2 you can use the DateTime constant

    gmdate(DATE_RFC2822, $timestamp)

an example of it’s use:

header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified).' GMT');
comments powered by Disqus