Return to Previous Page after updating


I am in an update form and have the link in the link to update, for example: view_fases.php?iddrs=2

I send it to update, and all good the problem comes when I want to finish making the changes I return to the same page with the id that was updated, How could I place it in header depending on the id that was updated :

asked by laura 16.06.2016 в 20:16

2 answers


You can do what you mention in the comments of javascript:history.back(-1) , but that can present some problems:

  • If the user has JavaScript disabled, it will not work directly.

  • The user can see a blank window before redirecting to the previous page.

  • JavaScript is an intermediary that is doing something you could do directly with PHP.
  • Doing a history.back(-1) can dislocate the web application (although if this happens, you have more serious problems).

That's why I would recommend that you redirect it directly with PHP, using the function header that you also mention in the question. For what you comment, all you need to do is pass the parameter with the ID. But that's simple if the URL is view_fases.php?iddrs=2 then your code would be something like this:


    // lee el valor del parámetro iddrs
    $iddrs = $_GET["iddrs"];

    // haz las operaciones que tengas que hacer para la actualización
    // ...

    // redirecciona a la página anterior
    header("Location:view_fases.php?iddrs=" . $iddrs);

An important fact to keep in mind: the redirection with header will give an error if some content has been written before (with echo , print , var_dump , etc.), because it can not be changed the header information once the data output has started.

answered by 17.07.2016 в 15:19

you must call the GET that is up in the browser bar iddrs=(NUMERO) with a function like this:

answered by 17.06.2016 в 02:49