By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,407 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,407 IT Pros & Developers. It's quick & easy.

Conditionals Help!

P: n/a
Ok, I'm having some trouble with conditionals, for some reason PHP is screwing them up.
First off, here is the code:

<?php
$username = "fred";
$userdata = "./$username.txt";
$fp = fopen("$userdata", "r", 1);
$origpass = fread($fp, 5);
if($passcount = 1)
{
if($pass = $origpass)
{
echo "Welcome to the Members' Only Part of the Site!";
}
else
{
echo "Sorry, wrong password, please try again:";
echo "<form method='post' action='authenticationtest.php'>";
echo "<input name='pass' type='text'>";
echo "<input name='passcount' type='hidden' value='1'>";
echo "<input type='submit'>";
echo "</form>";
}
}
else
{
echo "Please input your password below:";
echo "<form method='post' action='authenticationtest.php'>";
echo "<input name='pass' type='text'>";
echo "<input name='passcount' type='hidden' value='1'>";
echo "<input type='submit'>";
echo "</form>";
}
fclose($fp);
?>

Its a relatively simple authentication script. It reads a password from a text file and compares it to the
value sent previously. The problem seems to be one of two things:

The first, is that PHP takes the wrong else statement, it goes from the first if (about $passcount) and then
goes directly to the else statement with the sorry form. It never goes down to the correct else!

Secondly, it seems that for some reason after a successful login, it will forevermore only display welcome.
I don't have any cookies set, nor sessions, so then how do I get it to logout? Need some help with that.

Thanks for any help in this!
Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Oh I see! Thanks a lot! It works great now!
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.