+2  A: 

Sounds like you know what to do already. If you want to store the URLs in a database, that's fine, but just imagine you've got a structure like this:

<?PHP
$routes = array(
'example.com/1.php'=>'example.com/2.php',
'example.com/2.php'=>'example.com/3.php',
'example.com/3.php'=>'example.com/4.php');

if (array_key_exists($_SERVER['HTTP_REFERER'],$routes)){
    header('Location: http://'. $routes[$_SERVER['HTTP_REFERER']]);
}else{
    header('Location: http://example.com/default.php');
}
exit;

?>
timdev
I'd love to hardcode it, but I'll have a few thousand of these forwards eventually, wouldn't that make the script a little bit slow to load?
You could always compare times using a database versus a giant list in the PHP file.Eventually, you'll cross the threshold where one is no longer faster than the other—just a matter of when.
Nerdling
True, for very large datasets a database would likely be faster (and perhaps easier to administer). If you wanted to keep the map in a flat file, you could always try to sprinkle in some in-memory caching using memcache or apc, if they're available.
timdev
I think I'll just have separate files. Since this is just a "next" button for me, I'll just make a next2 file when it gets slow