-2

So I have this website I am making, and I keep running the PHP files as well as the html files, but the PHP one does not work correctly.

HTML:

<!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>AUTHENTICATION</title>
</head>

<body>
    <form method="POST" action="PHP/password.php" style="text-align:center">
    ENTER THE AUTHENTICATION CODE: 
    <input type = "password" name = "password" value = "">
    <input type = "submit" value = "submit">
    </form>
</body>
</html>

PHP:

<?php

if (isset($_POST['submit']))
{
$pass = $_POST['password']
if ($pass == "111")
{
    header("Location: ../HTML/index1.html");
}else
{
    {?>
        <form method="POST" action="../PHP/password.php" style="text-align:center">
        ENTER THE AUTHENTICATION CODE: 
        <input type = "password" name = "password" value = "">
        <input type = "submit" value = "submit">
        <br />
        <font color = "red">incorrect password!</font>
        </form>
        <?}

    }
}

?> 

The PHP is supposed to get what you typed, and if it is equal to "111" it redirects you to a different part of the website. If it does not, it tells you the password is incorrect, and runs the else. But, no matter what I type, it considers the password "wrong" and does the "else" part of the code. Any help?

picture of directory: https://gyazo.com/7d49b063cd5dfaf6405e3704b3f3fa96

NOTE: I do NOT care about changing this to be more secure as it is a hobby I am working on.

P0150N
  • 25
  • 5

2 Answers2

3

Like others already said, submit is not a value you are sending, instead of that try this

if (!empty($_POST))

then you will get something like this..

<?php

if (!empty($_POST)){
   $pass = $_POST['password']

if ($pass == "111"){
    header("Location: ../HTML/index1.html");
}else{
    {?>
        <form method="POST" action="../PHP/password.php" style="text-align:center">
        ENTER THE AUTHENTICATION CODE: 
        <input type = "password" name = "password" value = "">
        <input type = "submit" value = "submit">
        <br />
        <font color = "red">incorrect password!</font>
        </form>
        <?}

    }
}

?> 

I would personally change the html for the php file and then you wont need to duplicate the form code.. only send a parameter or error and then be able to read it and display it at your screen.

Rename login to login.php and do this

<?php
if (!empty($_POST)){
   $pass = $_POST['password']

    if ($pass == "111"){
        //wherever you want to go after login
    }else{
       $password = false;
    }
}
?>
    <form method="POST" action="#" style="text-align:center">

        ENTER THE AUTHENTICATION CODE:

        <input type = "password" name = "password" value = "">
        <input type = "submit" value = "submit">
        <br />
        <?php if(isset($password) && ($password != true){ ?>
        <font color = "red">incorrect password!</font>
         <?php } ?> 
        </form>
jpganz18
  • 5,154
  • 15
  • 59
  • 111
  • Sorry i'm new to this, how would I make it load the PHP file if I can only run an HTML one? Is there code that can redirect like that? – P0150N Feb 06 '16 at 04:32
  • I also have another question. When I attempt to run the PHP, it asks to download it. Any help? (this server is hosted on dropbox) – P0150N Feb 06 '16 at 05:53
  • That is because you need to add the proper application type (try addType) or because you have missing modules... check this other question that is related http://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them – jpganz18 Feb 08 '16 at 15:21
  • Reading about dropbox, I doubt you can configure it the way you want it, I recommend you to locally install XAMPP or WAMPP and later find a hosting that meets all the php module requirements – jpganz18 Feb 08 '16 at 15:23
1

You do not have an input named submit. So when you run your code, $_POST['submit'] returns an unidentified index, which you probably do not see, because your error_reporting is off.

Try adding

<input type="hidden" name="submit" value="true">

in your html.

You do, however, have an input with type="submit", but that is only a button, so you have you no luck there.

Alex Karshin
  • 12,300
  • 14
  • 50
  • 60
  • @P0150N `error_reporting(-1);` or in your `php.ini`. See the manual: http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors – Alex Karshin Feb 06 '16 at 00:29