我正在尝试制作一个受密码保护的网站。密码目前只是硬编码,以便我更容易测试。
我遇到的问题是,当我输入实际密码时,cookie 似乎没有设置。如果我第二次重新输入密码,那么 cookie 就会被设置。
我知道问题在于我调用代码的顺序,但我很难确定我应该更改什么以使其在第一个正确的密码输入时正确运行。任何帮助,将不胜感激。
case 'Maintenance':
$salt = "test";
$adminpass = "adminpass";
$RealPassword = crypt($adminpass, $salt);
function LoginScreen($SaltCode){
?>
<html>
<head>
<title>Please enter password to access this page</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>
<style>
input { border: 1px solid black; }
</style>
<div style="width:500px; margin-left:auto; margin-right:auto; text-align:center">
<form method="post">
<h3>Please enter password to access this page</h3>
<font color="red"><?php echo $error_msg; ?></font><br />
<input type="password" name="access_password" /><p></p><input type="submit" name="Submit" value="Submit" />
</form>
<br />
</div>
</body>
</html>
<?php
global $PasswordEntered;
$PasswordEntered = crypt($_POST['access_password'],$SaltCode);
}
if (!isset($_COOKIE["Cookie"]))
{
LoginScreen($salt);
if ($PasswordEntered == $RealPassword)
{
setcookie("Cookie", $PasswordEntered, time()+600);
}
}
if (isset($_COOKIE["Cookie"]))
{
?>
<B><fontsize=16>Are you sure you want to Format the data disk?</b></font><br><br>
<form method = "post">
<INPUT TYPE = 'Submit' name = 'FormatSubmit' value = 'Submit'>
<br><br><br>
Please check the box to verify you want to Format the data disk.
<Input type = "Checkbox" Name ="FormatCheck" value ="checked">
</form>
<?php
if (($_POST['FormatSubmit'] == "Submit") & ($_POST['FormatCheck'] == "checked"))
{
html_exec_cmd('echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/sda;sleep 1;mkfs.ext3 /dev/sda1;mount /dev/sda1 /data/');
}
}
break;