MegaCleptomaniac
MegaCleptomaniac

Reputation: 133

PHP HTML won´t load

I wrote the following PHP but if I enter my password correct my HTML code won´t show up and just an empty page is shown .

Here is the code:

<?php
$pass = $_POST['pass'];
if ($pass == "password") 
{
?>  
   <html>
   <head>
        <title>ADMINISTRATION</titel>
        <meta charset="utf-8">
   </head>
   <body>
        <h3>Reset Database</h3>
        <form action="DB_Reset.php" method="post">
            <input type="submit" value="RESET DATABASE">
        </form>
    </body>
    </html>
<?      
}
else
{
    function Redirect($url, $permanent = false)
    {
        header('Location: ' . $url, true, $permanent ? 301 : 302);
       exit();
    }
    Redirect('/index.php', false);
}
?>

I know that this method of working with passwords is not the safest but for the beginning it should work out. The redirection in case of a wrong password is working but not the HTML code as mentioned before.

Upvotes: 1

Views: 55

Answers (2)

A Misrhra
A Misrhra

Reputation: 1

Try this

<?php

if (isset($_POST['pass']) && ($_POST['pass'] == "password")) 
{
?>  
<html>
<head>
    <title>ADMINISTRATION</titel>
    <meta charset="utf-8">
</head>
<body>
    <h3>Reset Database</h3>
    <form action="DB_Reset.php" method="post">
        <input type="submit" value="RESET DATABASE">
    </form>
</body>
</html>

<?php      
}
else
{
    function Redirect($url, $permanent = false)
{
    header('Location: ' . $url, true, $permanent ? 301 : 302);

    exit();
}
Redirect('/index.php', false);
}
?>

Upvotes: 0

Disha V.
Disha V.

Reputation: 1864

<?php
if(isset($_POST)){
    $pass = $_POST['pass'];
    if ($pass == "password") 
    {
        /* do your stuff */
    }
    else
    {
        header('Location: ' . $url, true, $permanent ? 301 : 302);
    }
}
?>  
<html>
<head>
    <title>ADMINISTRATION</titel>
    <meta charset="utf-8">
</head>
<body>
    <h3>Reset Database</h3>
    <form action="DB_Reset.php" method="post">
        <input type="password" name="pass" />
        <input type="submit" value="RESET DATABASE">
    </form>
</body>
</html>

Upvotes: 1

Related Questions