ログインフォームを投稿し、確認/ログイン/すべてを行った後、header('location:someOtherPage.php)別のページにリダイレクトします。その後、f5キーを押してもフォームを再投稿できなくなります。例えば:
//login.php
<?php
//no cache headers if you want.
session_start();
if(isset($_POST) && !empty($_POST)){
//validate user & pass. if valid set session then...
if(is_valid_user()){
//set session
$_SESSION['loggedIn'] = true;
//close session. this prevents problems with vars not
//setting when using a header redirect because you redirect
//before the session file can write.
session_write_close();
//redirect to another page
header('location:loggedIn.php');
//stop the script from running
exit;
} else {
echo "<div class='error'>Login failed.</div>";
}
}
//echo login form.
?>
ヘッダーリダイレクトは履歴に表示されないため、押し戻すと、フォームを再投稿できるページは表示されません。