我想出了如何将用户信息从注册页面写入 .dat 文件,但我一直在尝试通过与 .dat 进行交叉检查来验证登录页面上的用户是否匹配。
我的登录页面代码包括:
<?php
include "functions.inc";
// Useful variables
$datafile = "users.dat";
if (array_key_exists('submit', $_POST))
// Function to check the password length
{
$the_user = $_POST['newuser'];
// Load the file of users and store it in $users
$users = arrayfile_to_array($datafile);
$users = arrayfile_to_array($datafile);
// Validate user name and password
}
else
{
$users = arrayfile_to_array($datafile);
// Validate the email address
if (!user_unique($users, $the_user['newuser']))
echo "User already exists!";
}
if (array_key_exists('submit', $_POST))
// Function to check the password length
{
header('Location: 04invoice.php');
}
else
if (array_key_exists('register', $_POST))
{
header('Location: 03registration.php');
}
?>
<!DOCTYPE html>
<html> <center>
<style>
body
{
background-color:aqua;
font-family:"Times New Roman";
font-size:20px;
}
h1
{
color:orange;
text-align: center;
}
p
{
font-size:24px;
}
table
{
background-color:green;
font-family:"Helvetica";
font-size:20px;
font-weight:bold;
}
</style>
<h1>
Welcome to the Pay'N'Go Kiosk
</h1>
<body>
<form action= "<?php $_SERVER["PHP_SELF"] ?>" method="POST">
<p>Username: <br>
<input style="background-color: yellow; color:black" type='text' name='username'
value='<?php if(isset($_POST['newuser[username]']))
echo $_POST['newuser[username]'] ?>'>
<BR>
Password: <br>
<input style="background-color:magenta" type='password' name='newuser[password]'><BR>
<input type='submit' name='submit' value='Sign In'>
<br/>
Not a user? Sign up today! </br>
<a href='03registration.php'>register here!</a>
</form>
</body>
</center>
</html>
我正在尝试使用 arrayfile_to_array 来调出包含所有数组的文件,但我不知道如何使用它。任何提示将不胜感激。
// Open the file
// If the file doesn't exist, create it.
if (!file_exists($datafile))
{
$users = array();
array_to_arrayfile($users, $datafile);
}
else
{
$users = arrayfile_to_array($datafile);
}
}