There is a handler for adding a comment:

if (isset($_POST['CommentEnter'])) { $text = $_POST['text']; $mark = $_POST['mark']; $idproduct = $params[1]; $text = stripslashes($text); $text = htmlspecialchars($text); $text = trim($text); $add = new Model_Product(); $add->add_comment($idproduct,$text, $mark); } 

So after adding a comment, I would like to forcibly reload the page so that the added comment becomes visible, how to do it?

  • 2
    well, if no headers have been output to output yet, then header('Location: http://www.example.com/'); exit; header('Location: http://www.example.com/'); exit; ... php.net/manual/ru/… ... if everything was already there echo "<script>window.location = 'http://www.example.com/'; </script>"; ...... but in general in the modern world everything is done through ajax without rebooting .... that is, you need to send a request to the server via Ajax, it will return the value, and on the client the script will add an entry to the DOM - Alexey Shimansky
  • @ Alexey Shimansky, I was hoping to figure it out without ajax, since I’m still in it for 0, but I’ll probably have to implement it. - Denis

1 answer 1

You can do the following:

 if (isset($_POST['CommentEnter'])) { $text=$_POST['text']; $mark=$_POST['mark']; $idproduct = intval($params[1]); $text = stripslashes($text); $text = htmlspecialchars($text); $text = trim($text); $add = new Model_Product(); $add->add_comment($idproduct,$text, $mark); header('Location: /ru/product/details/' . $idproduct); exit(); } 
  • tell me, my address looks like " ru / product / details / 3 ", where the number 3 is stored in a variable, how can I correctly write this link in the header? - Denis
  • @Denis corrected the answer - cheops