Log in

View Full Version : My password code doesn't seem to work...



SessTehKing
04-04-2007, 12:55 AM
<?php

if(file_exists("".$_POST['name']."password.php")) {

include("".$_POST['name']."password.php");

if($real = $_POST['pass'])
{ Posting code here
} else { echo("Password is wrong.");}
} else {
$ft = fopen("".$_POST['name']."password.php", "a+");
fwrite($ft, "<?php
\$real = ".$_POST['pass']."
?>");

Posting code again
}
?>

This code should check if the file exists, and if it does, check if the password entered is the true password, and if that is right, then post. If not, say the password is wrong. And if the file doesn't exist yet, create it and write the password entered for the name (indicated by the file), then continue to post.

It always posts, no matter what.

Twey
04-04-2007, 10:18 PM
if($real = $_POST['pass']) Don't confuse assignment and comparison. == and === compare two values and return true or false depending on whether they are equal; = assigns the right-hand value to the left-hand value, then returns the right-hand value. For the purposes of that if statement, that may as well be:
if($_POST['pass'])

SessTehKing
04-05-2007, 04:56 PM
I noticed that and fixed it, but now it's acting as if the back to back else's aren't allowed...saying unexpected T_ELSE.

Twey
04-05-2007, 05:15 PM
Oh, yeah, that's not allowed either. You have to have a condition for each else clause.

SessTehKing
04-05-2007, 08:14 PM
That's why I have an if inside of an if, which is allowed, no? How am I supposed to handle that, then?