SilverHorn
SilverHorn

Reputation: 1026

php password, compare, return true or false

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!

Upvotes: 0

Views: 195

Answers (3)

Andre Dublin
Andre Dublin

Reputation: 1158

if ($text == "test")

not

if ($text) == "test"

Upvotes: 0

hakre
hakre

Reputation: 198217

That's very simple:

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

Or put it into the if clause directly:

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

Upvotes: 1

Pastor Bones
Pastor Bones

Reputation: 7371

if($password13)=="test"

should be

if($text=="test")

Upvotes: 6

Related Questions