0

i'm using a simple text document that holds a password in my site directory public_html/USERS/Matt/password.txt now the issue i'm having with my code is that when my submit button is pressed nothing seems to be happening. I'm sure it's just a silly mistake, anyone have any ideas here?

<?php
ob_clean();session_start(); 
if (isset($_GET['logout'])){
    session_destroy();  
}

$Username = $_POST['username'];
$EnteredPassword = $_POST['password'];

if (isset($_POST['submit'])){
    if (is_dir("USERS/".$Username) === true){
        $myFile=fopen("USERS/".$Username."/Password.txt","r") or exit("Can't open file!");
        $CorrectPassword = fgets($myFile);
        fclose($myFile);

        echo 'Username found.';

        if ($CorrectPassword == $EnteredPassword){
            echo 'Login successful.';   
        }

        else {
            echo 'Password incorrect.';
        }
    }

    else {
        echo 'Username not found.';
    }

    echo 'Checking if username is found...';
}

?>

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Project Archive - Login</title>

        <link href="CSS/master.css" rel="stylesheet" type="text/css">
        <script src="JAVASCRIPT/respond.min.js"></script>
    </head>
    <body>
    <div id="containerDiv">
        <div id="titleDiv">
            <font size="20pt">
                <p align="center">Project Archive</p>
            </font>

            <div id="loginBoxDiv">
                <form method="post" action="index.php">
                    <div id="username">
                        <p>Username:</p>
                        <input type="text" name="username" size="12">
                    </div>

                    <div id="password">
                        <p>Password:</p>
                        <input type="password" name="password" size="12">
                    </div>

                    <div id="btnLogin">
                        <input id="button" type="submit" value="Login">
                    </div>
                </form>
            </div>

        </div>
    </div>
    </body>
</html>
Matt Hutch
  • 453
  • 1
  • 6
  • 20

1 Answers1

2

Add name to the submit button

<div id="btnLogin">
     <input id="button" name='submit' type="submit" value="Login">
 </div>
Ravinder Reddy
  • 3,869
  • 1
  • 13
  • 22
  • Or just have `if($_SERVER['REQUEST_METHOD'] == 'POST')`, which is 100% reliable detecting a post submission. versus checking for a form field name which you may have typoed/forgotten. – Marc B Jun 10 '16 at 21:40