Results 1 to 10 of 10

Thread: Simple PHP password form

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Simple PHP password form

    I'm trying to make a form only submitable after entering a username and password but can't seem to get it to work. The edit.php contains the php form there going to be editing.

    PHP Code:
    <?php
    $username 
    $_POST['user'];
    $password $_POST['password'];
    if (
    user=="name1" || user=="name2") {
    if (
    password=="thepassword") {
    include(
    "edit.php");
    }
    else
    {
    echo 
    "Username or Password not entered correctly please try again.";
    }
    }
    ?>
    The html that submits to that page...
    Code:
    <form method="post" action="word.php" style="border:#000000 2px solid; width:375px;">
    Username: 
    <input type="text" name="user" size="35" />
    <br />
    Password:
    <input type="password" name="password" size="35" /><br />
    <input type="submit" value="Submit Password" style="text-align:center;" />
    </center></form>
    This is what the edit.php contains don't know if it's displayable with the include but i hope it is...

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Edit Questions</title>
    </head>

    <body>
    <?php
    $ipi 
    getenv("REMOTE_ADDR");
    $httprefi getenv ("HTTP_REFERER");
    $httpagenti getenv ("HTTP_USER_AGENT");
    ?>
    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
    Your Name: 
    <input type="text" name="name" size="35" />
    <br />

    <textarea name="question" rows="4" cols="44"><?php 
    $myFile 
    "questions.txt";
    $fh fopen($myFile'r');
    $theData fread($fh20000000);
    fclose($fh);
    echo 
    $theData;
    ?></textarea>
    <br /><center>
    <input type="submit" value="Send Your Question" style="text-align:center;" />
    </center></form>
    </body>
    </html>

    Thanks for any help and suggestions you can offer.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    or another way...???

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    These lines:

    Code:
    if (user=="name1" || user=="name2") {
    if (password=="thepassword") {
    should be this:

    Code:
    if ($username=="name1" || $username=="name2") {
    if ($password=="thepassword") {
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. The Following User Says Thank You to thetestingsite For This Useful Post:

    bluewalrus (10-13-2008)

  5. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Nope still no luck. I put what the include was suppose to bring in straight into the document but it didn't help. The password parts not being read for some reason. This is the php/ html mixture i have concocted:
    PHP Code:
    <?php
    $username 
    $_POST['user'];
    $password $_POST['password'];
    if (
    username=="name1" || username=="name2") {
    if (
    password=="password") {
    ?>
    <form method="post" action="submitques.php" style="border:#000000 2px solid; width:375px;">
    Your Name: 
    <input type="text" name="name" size="35" /><br />
    <textarea name="question" rows="4" cols="44">
    <?php
    $myFile 
    "questions.txt";
    $fh fopen($myFile'r');
    $theData fread($fh20000000);
    fclose($fh);
    echo 
    $theData;
    ?>
    </textarea>
    <?php
    }
    else
    {
    echo 
    "Username or Password not entered correctly please try again.";
    }
    }
    ?>
    Less the html and css stuff which can be seen here http://www.travelinchucks.com/word.php. The error message "username password not correct" doesn't come up. Seems to be ignoring it all together. The page thats submitting to this page is http://www.travelinchucks.com/log.php. Its all html with this form:
    Code:
    <form method="post" action="word.php" style="border:#000000 2px solid; width:375px;">
    Username: 
    <input type="text" name="user" size="35" />
    <br />
    Password:
    <input type="password" name="password" size="35" /><br />
    <input type="submit" value="Edit Page" style="text-align:center;" />
    </center></form>

  6. #5
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Code:
    $username = $_POST['user'];
    $password = $_POST['password'];
    if ($username=="name1" || $username=="name2") {
    if ($password=="password") {

  7. The Following 2 Users Say Thank You to allahverdi For This Useful Post:

    bluewalrus (10-13-2008),Clark Wells (10-18-2008)

  8. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    oooo hah I knew i was missing something else thanks. Do you know why the error message isn't working though?

  9. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this for your else section:

    Code:
    <?php
    }
    }
    
    else
    {
    echo "Username or Password not entered correctly please try again.";
    }
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. The Following User Says Thank You to thetestingsite For This Useful Post:

    Clark Wells (10-18-2008)

  11. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That brings up "Parse error: parse error, unexpected '}' in /hsphere/local/home/crazychr/travelinchucks.com/word.php on line 68". Maybe because i closed the php then reopened it down more?

    Code html and php:
    PHP Code:
    <?php
    $username 
    $_POST['user'];
    $password $_POST['password'];
    if (
    $username=="name1" || $username=="name2") {
    if (
    $password=="password") {
    ?>
    <form method="post" action="submitques.php" style="border:#000000 2px solid; width:750px;">
    <textarea name="question" rows="20" cols="90">
    <?php
    $myFile 
    "questions.txt";
    $fh fopen($myFile'r');
    $theData fread($fh20000000);
    fclose($fh);
    echo 
    $theData;
    ?>
    </textarea>
    <input type="submit" value="Submit Changes" style="text-align:center; font-family:Geneva, Arial, Helvetica, sans-serif; font-size:14px;" />
    </form>
    <?php
    }
    }
    else
    {
    echo 
    "Username or Password not entered correctly please try again.";
    }
    }
    ?>

  12. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You have an extra closing bracket. Simply remove the highlighted:

    Code:
    <?php
    $username = $_POST['user'];
    $password = $_POST['password'];
    if ($username=="name1" || $username=="name2") {
    if ($password=="password") {
    ?>
    <form method="post" action="submitques.php" style="border:#000000 2px solid; width:750px;">
    <textarea name="question" rows="20" cols="90">
    <?php
    $myFile = "questions.txt";
    $fh = fopen($myFile, 'r');
    $theData = fread($fh, 20000000);
    fclose($fh);
    echo $theData;
    ?>
    </textarea>
    <input type="submit" value="Submit Changes" style="text-align:center; font-family:Geneva, Arial, Helvetica, sans-serif; font-size:14px;" />
    </form>
    <?php
    }
    }
    else
    {
    echo "Username or Password not entered correctly please try again.";
    }
    }
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  13. The Following 2 Users Say Thank You to thetestingsite For This Useful Post:

    bluewalrus (10-14-2008),Clark Wells (10-18-2008)

  14. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    yea thats it thank you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •