2016-03-26 2 views
0

は...PHPのログインでpost-get-directを実装するにはどうすればよいですか?

私のコードは、あなたの基本的なPHPのパスワードスクリプトです...私はとにかく理解できること、それについての情報の多くはありませんので、新しいものをポストリダイレクトが-getのです

<?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; 
?> 

私はさまざまな方法を試しましたが、これは私が必要とする正確な方法であるようですが、コマンドの代わりに手続きのようなものです。誰も助けることができますか?

答えて

1

だけ$_SESSION['loggedIn'] = true;

+0

header("Location: ".$_SERVER["PHP_SELF"]);を追加するには、私はまだGET部分を把握しようとすると、あなたに感謝、しかし、あなたの方法は、私はしばらくの間、それを勉強するつもりです動作します。 – malanno

関連する問題