Conditionals Help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FHuang

    Conditionals Help!

    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("$userdat a", "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='authent icationtest.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='authent icationtest.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!
  • FHuang

    #2
    Re: Conditionals Help!


    Oh I see! Thanks a lot! It works great now!

    Comment

    Working...