Skip to content

Instantly share code, notes, and snippets.

@albyr
Created December 18, 2012 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albyr/4327346 to your computer and use it in GitHub Desktop.
Save albyr/4327346 to your computer and use it in GitHub Desktop.
Example PHP file for generating ETags for Little Printer publications.
<?php
// You need to pick one of the following lines, based on how often your publication will be updated
// The value of the 'date' function will then be hashed to produce the ETag
// date = date(z); // Generates ETag based on the day of the year, so publication updates daily
// date = date(W); // Generates ETag based on the week number, so publication updates on Monday of each week
// date = date(F); // Generates ETag based on the month, so your publication updates monthly
date = date(c); // Generates ETag based on the current date and time, so your publication updates every second (but will only be polled by BERG Cloud for each user once per day at the scheduled time)
// Generates MD5 hash of your given value
$md5 = md5($date);
// Sets the previously generated hash value as the page's ETag
header("ETag: ".$md5);
?>
<!-- Begin HTML for your publication -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
@wmucheru
Copy link

Really neat 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment