PHP <form action = 'XXX.php' method = &

2019-09-09 02:45发布

问题:

this is form code:

<div class="login_cont">
<form action="doLogin.php" method="post">
        <ul class="login">
            <li class="l_tit">管理员帐号</li>
            <li class="mb_10"><input type="text"  name="username" placeholder="请输入管理员帐号"class="login_input user_icon"></li>
            <li class="l_tit">密码</li>
            <li class="mb_10"><input type="password"  name="password" class="login_input password_icon"></li>
            <li class="l_tit">验证码</li>
            <li class="mb_10"><input type="text"  name="verify" class="login_input password_icon"></li>
            <img src="getVerify.php" alt="" />
            <li class="autoLogin"><input type="checkbox" id="a1" class="checked" name="autoFlag" value="1"><label for="a1">自动登陆(一周内自动登陆)</label></li>
            <li><input type="submit" value="" class="login_btn"></li>
        </ul>
    </form>
</div>

this is doLogin.php

include_once '../include.php';

$username = $_POST['username'];
$password = md5($_POST['password']);
$verify = $_POST['verify'];
$session_verify = $_SESSION['verify'];
print_r($_POST);
var_dump($_SERVER);

this is var_dump($_SERVER) result

why var_dump($_POST) is null?

回答1:

It is not possible to have var_dump($_POST) is null!

AS when you do

$username = $_POST['username'];
$password = md5($_POST['password']);
$verify = $_POST['verify'];
$session_verify = $_SESSION['verify'];
var_dump($_POST);

You'll get

array(3) { ["username"]=> string(8) "shashank" ["password"]=> string(8) "password" ["verify"]=> string(3) "123" }

If you pass username,password and verify blank even!

 var_dump($_POST); 

will be

array(3) { ["username"]=> string(0) "" ["password"]=> string(0) "" ["verify"]=> string(0) "" }

so as you've posted var_dump($_POST) is null has does't make any sense or not possible.

Funny Edit :)

It is only possible when you type username as null password as null etc will produce

array(3) { ["username"]=> string(4) "null" ["password"]=> string(4) "null" ["verify"]=> string(4) "null" }