1

in administration i have simple list of users ( 1 line = 1 user ). And as it used to be I have a button for "EDIT" and button for "DETAIL". And here it is how each line looks like:

enter image description here

When user click on detail or edit it redirect him on new address (something like detail/24 (where 24 is ID) or edit/24

Question is:
1# How can I redirect user from detail to page he came from ( because of paginator it is important to redirect on specific page like: list.php?page=4

2# How can I redirect user from edit if he press something like SAVE which basicly reload edit page so he is not able to store it anywhere.

In another words for #2, user is on page list.php?page=4 and click EDIT so he get to something like /edit/32 on that page he make some changes and press SAVE button. When he click this button PHP send FORM and refresh page.

Is there a way to redirect user on page list.php?page=4 without knowing if he press SAVE or not?

3# Is there some other way how to redirect on last page? which simulate "GO BACK" button in browser?

Andurit
  • 5,612
  • 14
  • 69
  • 121

2 Answers2

2

2# Location.reload()

location.reload();

1# and 3# Window.history

<button onclick="goBack()">Go Back</button>

<script>
     function goBack() {
         window.history.back();
     }
</script>
CoderPi
  • 12,985
  • 4
  • 34
  • 62
  • Hey @CodeiSir, thank you for your asnwer, answer number #1 and #3 looks great however I think I didnt explain #2 correctly. Please check my edit – Andurit Dec 07 '15 at 13:16
  • I still don't understand #2 – CoderPi Dec 07 '15 at 13:20
  • I'm sorry man. Looks I'm not good in explenation. Tradicionaly if you have page in PHP / HTML , you send FORM to PHP script so something like :
    (its simple example but should be enaugh) So when form is send page reload. Which means that history.back () is the same page as we are atm :) So if i press save my list.php page is 2 sites back not 1
    – Andurit Dec 07 '15 at 13:26
  • I understand. This should be done via PHP. There you can set `header()` with a redirect to the previous page. http://stackoverflow.com/questions/5285031/back-to-previous-page-with-header-location-in-php `header('Location: ' . $_SERVER['HTTP_REFERER']);` – CoderPi Dec 07 '15 at 13:31
2

If you want to redirect before rendering the HTML, I sugest you use header with $_SERVER global variable.

if($condition === true)
header('Location: '.$_SERVER['HTTP_REFERER']);

$_SERVER['HTTP_REFERER'] (http://php.net/manual/en/reserved.variables.server.php) returns the url of the page the user comes from.

Please note header function will only works if there no output before the call.

Hope can help!

Rafael Basso
  • 112
  • 5