douwen9343 2013-11-08 06:00
浏览 16

验证用户从.dat文件登录的问题

I figured out how to write user info from a registration page to a .dat file but I am stuck at trying to validate a user on the sign in page by cross checking with the .dat if their information matches.

My sign in page code consists of this:

<?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>

I am trying to use arrayfile_to_array to bring up the file with all the arrays but I am lost as to how to use it. Any tips would greatly be appreciated.

 // 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);
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?