带有PHP动作的HTML表单

时间:2016-08-12 11:52:56

标签: php html variables authentication

根据下面的代码,在按下提交按钮并且login_process.php完成其任务后会发生什么? HTML是否继续从评论的位置开始?

如果答案是肯定的,那么从PHP页面传递以下内容的最佳方法是什么?

  • 身份验证通过或失败
  • PHP页面中的变量(个人资料信息)

为简洁起见,删除了样式部分。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Login Page</title>     
    </head>
    <body>
        <!-- Begin Page Content -->
        <div id="container">
            <form action="login_process.php" method="post">
                <label for="loginmsg" style="color:hsla(0,100%,50%,0.5); font-family:"Helvetica Neue",Helvetica,sans-serif;">
                    <?php  echo @$_GET['msg'];?>
                </label>
                <label for="username">Username:</label>
                <input type="text" id="username" name="username">
                <label for="password">Password:</label>
                <input type="password" id="password" name="password">
                <div id="lower">
                    <input type="checkbox">
                    <label class="check" for="checkbox">Keep me logged in</label>
                    <input type="submit" value="Login">
                </div><!--/ lower-->
            </form>
        </div><!--/ container-->
        <!-- End Page Content -->
    </body>
</html>

1 个答案:

答案 0 :(得分:-1)

按下提交按钮后,login_process.php完成其任务后会发生什么情况取决于您希望“login_process.php”文件的代码执行的操作。您可以重定向它,或者只是打印问候语或验证您的表单获取其字段的值或您想要完成的任何内容。

对于身份验证, 1 - 通过$ _POST []数组获取表单的字段值 2 - 使用您的数据库值验证收到的数据。 3 - 相应地采取行动。

查看this教程,该教程将指导您如何在PHP中进行身份验证。