PHP密码问题

PHP密码问题,php,passwords,Php,Passwords,我的服务器上有一个名为“pform.php”的文件,它看起来是这样的: <form action="password.php" method="get"> <input type="text" name="password13"/> <input type="submit" value="Submit!"/> </form> <?php $text=$_GET["password13"]; $right="You entered the

我的服务器上有一个名为“pform.php”的文件,它看起来是这样的:

<form action="password.php" method="get">
<input type="text" name="password13"/>
<input type="submit" value="Submit!"/>
</form>
<?php

$text=$_GET["password13"];
$right="You entered the right password!";
$wrong="You entered the wrong password!";

if($password13=="test")
{
    echo $right;
}
else
{
    echo $wrong;
}
?>

我将其传输到另一个名为“password.php”的文件,它看起来是这样的:

<form action="password.php" method="get">
<input type="text" name="password13"/>
<input type="submit" value="Submit!"/>
</form>
<?php

$text=$_GET["password13"];
$right="You entered the right password!";
$wrong="You entered the wrong password!";

if($password13=="test")
{
    echo $right;
}
else
{
    echo $wrong;
}
?>

当我输入正确的密码时,它返回false


插入正确密码时,如何更改它以使其返回true?

您需要通过
$text
访问它,因为这是您定义的变量:

$text=$_GET["password13"];

// use $text, not $password13
if($text=="test")
{
    echo $right;
}
else
{
    echo $wrong;
}

检查$test,因为$password13不存在:-)


把你的代码改成这个。您的$password13变量未定义

我将更改您的表单,使其至少以
POST
的形式提交,并通过输入“password”来屏蔽密码

<form action="password.php" method="post">
<input type="password" name="password13"/>
<input type="submit" value="Submit!"/>
</form>

然后引用变量,如下所示:

<?php

$text=$_POST["password13"];
$right="You entered the right password!";
$wrong="You entered the wrong password!";
...

永远不要对敏感数据(如密码等)使用$\u GET参数,这些参数存储在浏览器缓存、服务器日志中,存在巨大的安全风险


像Jakub在上面为你写的那样使用$\u POST。

if($password13==“test”)
=>
if($text==“test”)
如果你从来没有声明过
$password13
,你需要使用
$text
,因为它被设置为
$\u GET[“password13”]
。下面提到的可能重复项,不要使用