2016-03-26 5 views
0

ist eine neue Sache, post-Redirect-bekommen, weil es nicht viele Informationen über sie ist, dass ich sowieso ...Wie implementieren Sie Post-Get-Direct mit einem PHP-Login?

Mein Code ist ein einfaches PHP-Skript Passwort verstehen könnte ..

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

Ich habe verschiedene Methoden ausprobiert, aber das scheint genau die Methode zu sein, die ich brauche, aber statt eines Befehls ist es mehr wie eine Prozedur. Kann jemand helfen?

Antwort

1

Fügen Sie einfach header("Location: ".$_SERVER["PHP_SELF"]); nach $_SESSION['loggedIn'] = true;

+0

danke, ich noch den get Teil zu erfassen versuchen, aber Ihre Methode funktioniert so für eine Weile Ich werde es studieren. – malanno

Verwandte Themen