if statement not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
petethepirate
Forum Newbie
Posts: 10
Joined: Sat Oct 04, 2008 5:33 pm

if statement not working

Post by petethepirate »

Im new to php5, and have been working on this for 3 days and cant figure out why its not working. Ok this is weird, I was editing the php file to post here and change $pass = $_POST["password"]; to $pass = $_POST["a"]; and it worked. I verified before and after the IF statement that both hashes did match. Can anyone see what Im doing wrong? Im new to php and dont quite have it figured out. Thanks. Heres the .php file.

<?php
ob_start();
session_start();
$pass = "a";
echo "<html>\n";
echo " <body>\n";
echo " <title>fix later</title>\n";
echo " </body>\n";;

$hpass = ("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");

$passwordHash = sha1($pass);

echo "<p>$hpass is hpass</p>\n";
echo "<p>$passwordHash is passwordHash</p>\n";

if ( $hpass == $passwordHash )
{
echo "<p>Welcome back $emailaddress</p>\n";
} else
{
echo "<p>Wrong password</p>\n";
}
echo "<p>$hpass is hpass</p>\n";
echo "<p>$passwordHash is passwordHash</p>\n";
?>
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: if statement not working

Post by josh »

you code does not reference the post data, you've hard coded an ascii character.
petethepirate
Forum Newbie
Posts: 10
Joined: Sat Oct 04, 2008 5:33 pm

Re: if statement not working

Post by petethepirate »

Yeah I did that so I didnt have to post 20 files.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: if statement not working

Post by josh »

print_r( $_POST );

if you're going to edit your code before you post it, how are we gonna spot the bug? Obviously if changing it to "a" worked, then the field must be called "a" in the form or whatever is posting to your script
Post Reply