My first real script! Password protect pages!

Discussion in 'PHP' started by Jake-Johnson, Oct 8, 2008.

  1. #1
    index.php:

    
    <html>
    <body>
    <form action="login.php" method="post">
    <input type="password" name="password" value="password">
    <input type="submit" value="Enter Website">
    </form>
    </body>
    </html>
    
    Code (markup):
    login.php:

    
    <html>
    <body>
    <?php
    if($_POST['password'] == yourpassword) {
    echo "Thanks, your password was entered correctly!";
    } else {
    echo "You have entered an incorrect password!";
    }
    ?>
    </body>
    </html>
    
    Code (markup):
    Very simple, :) I guess no cookies = bad but whatever, I'm a newby at PHP. >.<

    So when you enter "yourpassword" in the box, you get the + message :)
     
    Jake-Johnson, Oct 8, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    yep correct
     
    bartolay13, Oct 8, 2008 IP
  3. Jake-Johnson

    Jake-Johnson Peon

    Messages:
    839
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Lol, yes, correct.
     
    Jake-Johnson, Oct 8, 2008 IP
  4. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #4
    Does if($_POST['password'] == yourpassword) { work without quotation marks around 'yourpassword'?
     
    live-cms_com, Oct 8, 2008 IP
  5. Jake-Johnson

    Jake-Johnson Peon

    Messages:
    839
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yep... Its just seeing if that statment is true, not creating a new string.

    Test it out, I'll make a new live demo for you guys to see of this in action.
     
    Jake-Johnson, Oct 8, 2008 IP
  6. Jake-Johnson

    Jake-Johnson Peon

    Messages:
    839
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That same exact script, live:

    http://pbfrog.com/password

    Just type "yourpassword" and it will show the + message.
    Type anything else, and it will show the - message.
     
    Jake-Johnson, Oct 8, 2008 IP
  7. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #7
    Next time code a database driven login with registration. That'll be much more useful experience for you.
     
    live-cms_com, Oct 8, 2008 IP