0
echo "<p>Incorrect details, Username or password is incorrect\n" .
     '<br /><br /> <button onclick="history.go(-1);">Back </button></p>';

I am using the code above to redirect users if their login details are incorrect. The header won't work as I am outputting html and I need the button, the problem is on the page it goes back to. It displays the past errors if there were any before.
I have two pages one called login which is just a form which submits to this login process.

Schwesi
  • 4,753
  • 8
  • 37
  • 62
S.S
  • 101
  • 10
  • 1
    if you know the page they came from, you can just hard-code the link back to that page. that will act as a new request and avoid reloading the history / saved data. – mister martin Nov 29 '16 at 20:58
  • http://stackoverflow.com/questions/6320113/how-to-prevent-form-resubmission-when-page-is-refreshed-via-php – WEBjuju Nov 29 '16 at 20:58
  • Possible duplicate of [Reset a form through javascript that is called via php](http://stackoverflow.com/questions/13066571/reset-a-form-through-javascript-that-is-called-via-php) – Roshan Bhumbra Nov 29 '16 at 21:00
  • I didn't get it, you're saying that Header won't work BECAUSE you need the button or you THINK you need the button because Header won't work? – leoap Nov 29 '16 at 21:01
  • Yeah the header dont work as i use html at the start. I think button is my only choice, ill hardcode it and see how it works. – S.S Nov 29 '16 at 21:05
  • 1
    If you have already output anything to browser, you cannot use `header` to redirect, but you can look into using `ob_start` first in order to make user of `header`http://stackoverflow.com/questions/11823130/how-to-redirect-with-header-location-in-php-when-using-ob-start#11823164 https://www.sitepoint.com/community/t/redirection-after-html-output/2351 – Adam T Nov 29 '16 at 21:09
  • If it does not necessarily have to be javascript history, you can use the HTTP_REFERER key of $_SERVER. https://www.electrictoolbox.com/php-http-referer-variable/ – Adam T Nov 29 '16 at 21:12

0 Answers0