Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
755 views
in Technique[技术] by (71.8m points)

html - PHP not able to access POST values

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.

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

This is my current source code:

Log in form:

<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 (as it currently stands):

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

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

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

What am I doing wrong here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...