It's fairly simple, but you'll need to either give us more information regarding your page setup or adapt this to fit your pages.
<?PHP
$pages = array('page1.php','page2.php','page3.php','page4.php');
// get current page number from GET variable, or use something like
// $_SERVER['script_name'] or whatever to pull the appropriate link
if (is_numeric($_GET['page'])) {
$curPage = $_GET['page'];
}
else {
$curPage = [default page number];
}
// total pages
$totalPages = sizeof($pages);
// back links
$prev = $curPage - 1;
if ($curPage = 1) {
echo "<< Back ";
}
else {
echo '<a href="'.$totalPages[$prev].'"><< Back</a>';
}
// mid links
for ($i = $curPage; $i < sizeof($totalPages); $i++) {
echo '<a href="'.$totalPages[$i].'">'.$i.'</a> | ';
}
// next link
$next = $curPage + 1;
if ($curPage < sizeof($totalPages)) {
echo '<a href="'.$totalPages[$next].'">Next >> ';
}
?>
That's really kludgy and might not even work, but you should be able to get the idea well enough to build a working function for it.
Edit: I'm wicked tired - just re-read your post, but this would work serviceably with sessions, if you wanted to go that route, instead of $GET, I suppose. I like $GET because it allows linking to say, page 4, but whatever you want. Hope I helped some.