PHP无法访问POST值 [英] PHP not able to access POST values

查看:278
本文介绍了PHP无法访问POST值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML登录表单,如果它们没有登录,它将被PHP处理并显示给用户。这个表单被设置为POST到/user.php,后者访问我的认证类,并创建一个会话并返回true或false,并且不会登录用户。

I have a HTML login form that is processed and displayed to the user by PHP if they are not logged in. This form is set to POST to /user.php which in turn accesses my authentication class, and either creates a session and returns true or false and does not log the user in.

我的问题是无论我尝试什么,HTML表单都不会将值传递到PHP处理部分。

My problem is that whatever I try, the HTML form simply will not POST values to the PHP processing part.

这是我目前的源代码:

登录表单:

<div class="panel-body">
                        <!-- BEGIN ifLogInError -->
                        <div class="alert alert-danger">
                            <p>Either your username or password was incorrect. Please try again. <a href="" class="alert-link">Forgotten your password?</a></p>
                        </div>
                        <!-- END ifLogInError -->
                        <form class="form-horizontal" method="post" action="{ROOT}/user.php">
                            <div class="form-group">
                                <label for="username" class="col-sm-2 control-label">Username</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="username" value="" placeholder="Your username">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="password" class="col-sm-2 control-label">Password</label>
                                <div class="col-sm-10">
                                    <input type="password" class="form-control" id="password" value="" placeholder="Your password">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="submit" class="btn btn-default" value="Sign in" />
                                </div>
                            </div>
                        </form>
                    </div>

User.php(目前的状态):

User.php (as it currently stands):

echo "<pre>";
var_dump($_POST);
var_dump(file_get_contents("php://input"));
echo "</pre>";
phpinfo();

这两个var_dumps都会返回以下内容,表明表单不是POSTing:

Both var_dumps return the following, suggesting the form is not POSTing:

array(0) {
}
string(0) ""

我在这里做错了什么?

What am I doing wrong here?

推荐答案

t给出< input> sa 名称属性。

You haven't given your <input>s a name attribute.

这篇关于PHP无法访问POST值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆