php - Avoid resending data on page refresh -
i'm writing simple login system & i'd "get" self-redirection avoid resending data on refresh (post-redirect-get pattern). know there several ways doing that:
header('location:main.php');
echo '<body onload="window.location = \''.$http_server_vars['php_self'].'\'">body</body>';
echo '<meta http-equiv="refresh" content="0;url='.$http_server_vars['php_self'].'">';
there quesions:
- which method correct?
- why 3. method doesn't work?. redirect after when click "refresh" button still "do want resend data" message?
the "most correct" 1.
because http, make sure returning temporary redirect code, otherwise users proxies end unable use system. other 2 rely on browser implementation (well technically 1. too) , not guaranteed work.
however should consider 4. using ajax , not worrying problems of past century.
Comments
Post a Comment