【发布时间】:2015-09-10 08:22:44
【问题描述】:
我正在从文本文档中检索信息并尝试测试用户输入是否与文本文档中的任何信息匹配。
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<?php
$userpassfile = fopen("usernamepass.txt", "r") or die("Unable to open file!");
$username = $_POST["usernamepassword"];
$_SESSION['$usernamepassword'] = $_POST["usernamepassword"];
while(!feof($userpassfile)){
$line = fgets($userpassfile);
$users = explode("#", $line);
for($x=0; $x<sizeof($users); $x++){
if($users[$x]==$username){
header('Location: booking.php');
} else {
header('Location: login.php');
}
}
}
if($username=="ADMINadmin"){
header('LOCATION: admin.php');
}
fclose($usernamefile);
当它检查txt中的信息时,似乎只检查第一个和最后一个元素。我不知道为什么。我认为这是因为在 for 循环中有一个
【问题讨论】:
-
这可能是 MS-Windows 和所有其他系统上的行编码不同的问题。这可能会破坏 php 在文件中视为“行”的内容。
-
作为建议,不要使用文本文件进行用户/密码登录。会有几个危险的安全问题。
-
这只是一个项目。没有什么会被开发出来。