php password, compare, return true or false

♀尐吖头ヾ 提交于 2019-12-08 10:37:56

问题


I have a file on my server called "pform.php", this is what it looks like:

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

I have it transfer to another file called "password.php", this is what it looks like:

<?php

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

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

What can I change on line 7 that makes it compare the password "test" and return true or false?

Thanks!


回答1:


if($password13)=="test"

should be

if($text=="test")



回答2:


That's very simple:

$trueOrFalse = ($password13=="test");
if ($trueOrFalse) {
   ...

Or put it into the if clause directly:

if ("test" === $password13)
{
    ...



回答3:


if ($text == "test")

not

if ($text) == "test"


来源:https://stackoverflow.com/questions/8344827/php-password-compare-return-true-or-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!