私はユーザー名とパスワードを受け入れ、file.phpに送る基本的なフォームを持っていました。私が比較しているところでは、usernameとpasswordは既にpassword.txtにあるものと比較されます。htmlのPHPファイルに設定するとターゲットの場所が空白になる
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Authentication</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<div class="signin text-center">
<form action="file.php" method="POST">
<div class="form">Username:
<input type="text" name="username"></div>
<div class="form">Password:
<input type="Password" name="password"></div>
<input type="submit" value="Go">
</form>
</div>
</body>
</html>
PHP:
<html>
<head>
<title>Password test, page 2</title>
<head>
<body>
<?php
$name = $_POST['username'];
$pass = $_POST['password'];
//read the contents of our password file.
$myFile = "password.txt";
$fh = fopen($myFile, 'r');
$data = fgets($fh);
fclose($fh);
//echo the data from the text file
echo $data;
//print out an HTML line break
print "<br>";
//now we need to split our line of data from the text
//file so that we can do the comparison.
//split the text into an array
$text = explode(":",$data);
//echo the split user name
echo $text[0];
//print out an HTML line break
print "<br>";
//echo the split password
echo $text[1];
//assign the data to variables
$good_name = $text[0];
$good_pass = $text[1];
//print the variables
echo $good_name;
echo $good_pass;
//print out an HTML line break
print "<br>";
//compare the strings
if($name === $good_name && $pass === $good_pass){
echo "That is the correct log-in information";
}else{
echo "That is not the correct log-in information.";
}
?>
<br>
</body>
</html>
PASSWORD.TXTは 含まれています。私はKなどとパスワードとしてユーザー名を入力すると、それは私を与える
k個誤った出力、すなわちログインが正しくないしかし、私はパスワードを確認するための条件を削除する場合、それは私に正しいログインを与える。
フォームのパスワードが暗号化されているため、文字列と比較できない可能性があります。しかし、私は、HTMLフォームはパスワードを暗号化しないと考えています。
また、私は自分のコンピュータからこのサイトをホストしています。
ご協力いただきありがとうございます。ありがとう
私は、ある時点でこれでライブに行くつもりはないと思っています。 –
また、 'password.txt'に含まれるものの例を提供する必要があります。 –
ライブ公開しません。そうでなければ私のサイトは今何も構成されていません。 password.textには次のような単純な行が含まれています:kそれだけです。 –