you can't really be sure which page was the previous page. often it is the same page but with post data etc.
I would recommend the following (I hope I understood what you intend to do):
user is viewing some entry with unique ID 123
(say, on a script called view-item.php?id=123)
click "add comment" -> post.php?to_item=123
post.php dows the following:
-> show empty form which includes (besides other inputs):
1. <input type="hidden" name="to_item" value="<?=$to_item ?>">
so you remember where you came from!
2. <input type="submit" name="ok" value="Save">
(in my scripts I call it ok)
the <form> action is $_SERVER['PHP_SELF'] and method is POST, so the script posts to itself
(again, this how I personally like to do it)
when the script is posting to itself, it starts again but recognizes -
if($_POST['ok'])
that something has been submitted.
now it
- writes the comment's data to the database (or some other data storage)
- redirects to the item (thread, article) where the user has just posted to so he sees the item with his comment:
header("Location: view-item.php?id=".$_POST['to_item']"); // item id has been remembered in the form all the time