【发布时间】:2012-01-10 00:14:51
【问题描述】:
我正在尝试比较存储在一个平面文件中的几个数组值(我知道,mysql 要好得多,但它是一个分配,所以请忍受过时的方法)与某种形式从 $_POST 变量发送的用户凭据尽管文件中只有一行数据,但我不断收到以下错误:
注意:未定义的偏移量:./login.php 第 70 行中的 3
我在下面包含了一些有问题的代码行以及一些前导码和浏览器打印的结果(在基本的故障排除尝试中,我运行了一个 print_r 命令并清楚地返回了 2 个数组,但不能'不知道为什么……?)。
如果我可以添加任何有助于解决问题的其他信息,请告诉我 - 我非常愿意提供帮助。
用户注册数据是从 register.php 文件的这段代码中捕获的
<?php
$filename = '../../private_data/filewriting.php';
if (isset($_POST['register']) && count($errors)==0) {
// Submission was OK, so display thank-you message
$output .= '<p><strong>Thanks for registering with us! Please click <a href="index.php">here</a> to login to the site using your Username and Password</strong></p>';
$handle = fopen($filename, 'a');
fwrite($handle, "\n".$clean['fullname']."|".$clean['address']."|".$clean['postcode']."|".$clean['username']."|".$clean['password']);
fclose($handle);
}
?>
然后在 login.php 文件的这个片段中检查用户输入登录详细信息
<?php
$output = '';
$filename = '../../private_data/filewriting.php';
if (isset($_POST['submit']) && count($errors)==0) {
$lines = file($filename);
foreach ($lines as $line) {
$arr = explode('|', $line);
print_r($arr);
echo '<br />';
// The next line is the problematic line 70
if ($arr[3]==$clean['username'] && $arr[4]==$clean['password']) {
$_SESSION['username'] = $clean['username'];
$_SESSION['password'] = $clean['password'];
$output .= '<p><strong>Password and Username match - Thank you for logging in. Please continue to browse the site using the links above.</strong></p>';
}
}
}
?>
提交登录详情后该文件的输出如下:
数组 ( [0] => )
注意:未定义的偏移量:./login.php 第 70 行中的 3
数组([0] => 测试用户 [1] => 123 Shallot Street, The Big Onion [2] => BN21 0LK [3] => testuser [4] => 密码)
密码和用户名匹配 - 感谢您登录。
【问题讨论】:
标签: php