Good question. How you achieve that with php depends on your script. For instance, you could use query strings. Javascript is what I've used in the past. If you're interested, here it is:
<form>
<input type="button" OnClick="history.back()"; value="Back">
<input type="button" OnClick="history.forward()"; value="Forward">
</form>