'PHP, Returning to a calling Page after saving a record in a Edit page

Lets say I have a Page with a List (list.php).

I click on a row on that list to Edit that record. I go to a edit.php Page.

I have 3 buttons on that edit.php page. Save, Apply, Cancel

  1. Save button - Saves the Record and returns to the (list.php) Page
  2. Apply button - Saves Record but stays on the same page (edit.php)
  3. Cancel button - No save, just return to the (list.php) Page

But now image if I can access for edit that item on a different page. How do I return to that calling page?

  • Do I add a parameter(code) to the URL? something like a Page Origination Code?
  • Do I save the previous page URL in a session? (bad, they can right click open another page and that would be saved to session url)

Am just curious to how others return to a previous page after a SAVE.



Solution 1:[1]

you can the server variable $_SERVER['HTTP_referrer']. They are other ways also you can store in session the current page and use is processing page.

Solution 2:[2]

Adding a parameter to the URL is the only reliable though quote ugly way.

That's why such an in-place editions nowadays often being implemented using AJAX, and this very site is a perfect example.

However, there are different cases.
Login page is imperfect example for example, as you always have a form instead of just a link, and thus you can always store the current page in a hidden form field.

Another approach is possible if you are using some sort of front controller, and all requests actually being directed to the single index.php file which runs appropriate script based on the URI.

in this latter case you will need no more than mere a redirect to the current page.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PHP Connect
Solution 2