Many thanks, Mark. This works fine.
I should add that I`m using MODx Evo and slightly modified the code:
<?php
// Check if it's set, and if so set the ID to a placeholder to use in a template for example
if (is_numeric($_SESSION['prevpage'])) { $modx->setPlaceholder('prevpage',$_SESSION['prevpage']); }
// Set the prevpage var to the current resource ID (Revolution-style) so you can check it on the next pageview
$_SESSION['prevpage'] = $modx->documentObject['id'] ;
return $_SESSION['prevpage'];
?>
Two small problems:
1. The snippet displays the ’id’ and on the previous page and next. On this second page displays and its id (in place the snippet) and id of the previous page (in place a placeholder). If I commented return $_SESSION[’prevpage’]; - snippet not work.
2. Now complicate the task

Try to pass content. Change $modx->documentObject[’content’], but it does not work now.