如何使用 php 登录实施 post-get-direct?

How do you implement post-get-direct with a php login?

是post-redirect-get 一个新东西,因为它上面没有太多我能理解的信息...

我的代码是您的基本 php 密码脚本..

<?php
//put sha1() encrypted password here - example is 'hello'
$password = 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d';

session_start();
if (!isset($_SESSION['loggedIn'])) {
$_SESSION['loggedIn'] = false;
}

if (isset($_POST['password'])) {
if (sha1($_POST['password']) == $password) {
    $_SESSION['loggedIn'] = true;
} else {
    die ('Incorrect password');
}
} 

if (!$_SESSION['loggedIn']): ?>

<html><head><title>Login</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" title="1">
<style>
#formenclosure  {
width: 300px;
height:300px;
margin-top:50px;
margin-left:auto;
margin-right:auto;
color:fff;
}</style>
</head>
<div id="header">
    <div id="logo">
        <img src="images/zlogo1.png" width="36" height="42"
           title=<?php echo '"' . $_SERVER['HTTP_USER_AGENT'] .'"' ?>"
        >
    </div>
 <div id="enterprise">Palladium Z1 <span style="color:gold">&nbsp<?php echo $host ?></span></div> <p id='hmsg'></p>

</div>
<?php
 // Check the browser level and warn users if it looks wrong (not chrome or FF or too old an FF)
 // swap the beginning comments between the next two IF statements to see how the message looks.
if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox/3.')>0
    ||(   strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')==0
       && strpos($_SERVER['HTTP_USER_AGENT'],'Chrome' )==0
      )
   ) {
 // if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox/4')>0) {   /* for testing */
 //  echo "&nbsp;&nbsp; Unsupported Browser:" . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
 echo "&nbsp;&nbsp; Page best viewed with Chrome or Firefox (38.5 or later).";
}
?>
</div>
<body>
<div id="formenclosure">
<fieldset>
<legend>You need to login</legend>
<form method="post">
  Password: <input type="password" name="password"> <br />
  <input type="submit" name="submit" value="Login">
</form>
</fieldset>
</div>
<div id="footer">
            <div id='cadencelogo' title='Versions: <?php echo $verall ?>' >
                <img src="images/logocadence.jpg" width="160" height="36">
            </div>
</div>
</body>
</html>

 <?php
 exit();
 endif;
 ?>

我尝试了不同的方法,但这似乎正是我需要的方法,但它更像是一个程序,而不是命令。有人可以帮忙吗?

只需在 $_SESSION['loggedIn'] = true;

后添加 header("Location: ".$_SERVER["PHP_SELF"]);