How can a password-protected area be created in PHP without using a database?

To create a password-protected area in PHP without using a database, you can store the password in a PHP file and check the entered password against it. This method is suitable for small-scale applications where security requirements are not very high.

<?php
// Set the password
$password = "mysecretpassword";

// Check if the form has been submitted
if(isset($_POST['password'])) {
    // Check if the entered password matches the set password
    if($_POST['password'] == $password) {
        // Password is correct, display the protected content
        echo "Welcome to the protected area!";
    } else {
        // Password is incorrect, display an error message
        echo "Incorrect password. Please try again.";
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Password Protected Area</title>
</head>
<body>
    <form method="post" action="">
        <label for="password">Password:</label>
        <input type="password" name="password" id="password">
        <input type="submit" value="Submit">
    </form>
</body>
</html>