AutomaticPageRefresh

Summary: How to create pages that refresh automatically.
Version: 20171121
Prerequisites: pmwiki-2.0 (and possibly earlier)
Status: stable
Maintainer: Petko
Categories: Layout, PHP72

Description

This recipe makes it possible for a page to refresh at set intervals, or by an interval set in a ?refresh=nn addition to a page URL.

general automatic page refresh

The following will cause a browser to refresh the page every 30 seconds:

if ($action == 'browse')
    $HTMLHeaderFmt['refresh'] =
       "<meta http-equiv='Refresh' Content='30; URL={\$PageUrl}' />";

It can be done sitewide in local/config.php (probably not recommended, because it will work for all pages), or in a per-page or per-group customization file.

refresh markup

Alternatively, set individual page refresh with markup directive.
Example: page refresh every 20 seconds: (:refresh 20:)

# markup (:refresh nn:)
Markup('refresh', '<include',
  '/\\(:refresh\\s+(.*?):\\)/i',
  "RefreshMarkup");

function RefreshMarkup($m) {
  global $HTMLHeaderFmt;
  $secs = intval($m[1]);
  $HTMLHeaderFmt['refresh'] =
    "<meta http-equiv='Refresh' Content='$secs; URL={\$PageUrl}' />";
  return '';
}

refresh url parameter

Or, one could use the following customization to add a '?refresh=nn' option to all pages:

$rsec = intval(@$_GET['refresh']);
if ($rsec) {
   $HTMLHeaderFmt['refresh'] =
     "<meta http-equiv='Refresh' Content='$rsec; URL={\$PageUrl}?refresh=$rsec' />";
}

As a demonstration, this latter version is enabled at: Test.Refresh.

Release Notes

  • 20171121: Update for PHP 5.5 and 7.2, fix XSS vulnerability in '?refresh=nn' URLs.

See Also

  • SlideshowRefresh - uses the code above as a basis for a recipe that enables "slideshows" consisting of wikipages getting automatically loaded, one-after-another, via the Refresh meta tag.

Contributors

Comments

See discussion at AutomaticPageRefresh-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.