0
我正在使用一个简单的文本文件,它在我的网站目录public_html/USERS/Matt/password.txt中保存一个密码现在,我与我的代码存在的问题是,当我按下提交按钮时似乎没有任何事情发生。我确信这只是一个愚蠢的错误,任何人有任何想法吗?登录php代码没有做任何事情?
<?php
ob_clean();session_start();
if (isset($_GET['logout'])){
session_destroy();
}
$Username = $_POST['username'];
$EnteredPassword = $_POST['password'];
if (isset($_POST['submit'])){
if (is_dir("USERS/".$Username) === true){
$myFile=fopen("USERS/".$Username."/Password.txt","r") or exit("Can't open file!");
$CorrectPassword = fgets($myFile);
fclose($myFile);
echo 'Username found.';
if ($CorrectPassword == $EnteredPassword){
echo 'Login successful.';
}
else {
echo 'Password incorrect.';
}
}
else {
echo 'Username not found.';
}
echo 'Checking if username is found...';
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Project Archive - Login</title>
<link href="CSS/master.css" rel="stylesheet" type="text/css">
<script src="JAVASCRIPT/respond.min.js"></script>
</head>
<body>
<div id="containerDiv">
<div id="titleDiv">
<font size="20pt">
<p align="center">Project Archive</p>
</font>
<div id="loginBoxDiv">
<form method="post" action="index.php">
<div id="username">
<p>Username:</p>
<input type="text" name="username" size="12">
</div>
<div id="password">
<p>Password:</p>
<input type="password" name="password" size="12">
</div>
<div id="btnLogin">
<input id="button" type="submit" value="Login">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
或只是有'如果($ _ SERVER [ 'REQUEST_METHOD'] == 'POST')',这是100%可靠的检测后提交。与检查您可能打字/忘记的表单字段名称。 –