Skip to content

Instantly share code, notes, and snippets.

@terryupton
Last active August 29, 2015 14:23
Show Gist options
  • Save terryupton/e7637360fedc8e82b43e to your computer and use it in GitHub Desktop.
Save terryupton/e7637360fedc8e82b43e to your computer and use it in GitHub Desktop.
Set Last Modified Header
<?php
//MODIFIED HEADER DATE
##################################################################################
function set_headerdate() {
$format = "%a, %d %b %Y %H:%M:%S %z";
// First check if there is a blog post date
if (function_exists('perch_blog_post_field') && function_exists('perch_get') && perch_blog_post_field(perch_get('s'), 'postDateTime', true)) {
$result = perch_blog_post_field(perch_get('s'), 'postDateTime', true);
header("Last-Modified: ".strftime($format, strtotime($result)));
}
//If a list and detail page then get the date passed into the template/edited.
else if (class_exists('PerchSystem') && PerchSystem::get_var('modified_date')) {
header("Last-Modified: ".PerchSystem::get_var('modified_date'));
}
// If not then is there a perch modified date?
else if(function_exists('perch_page_modified') && perch_page_modified(array('format' => $format), true)) {
header("Last-Modified: ".perch_page_modified(array('format' => $format), true));
}
// Finally if not get the modified time-stamp of the actual file
else {
header("Last-Modified: ".strftime($format, filemtime($_SERVER['SCRIPT_FILENAME'])));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment