How can a password prompt be created in PHP?

To create a password prompt in PHP, you can use a simple HTML form with an input field for the password. Upon form submission, you can check if the entered password matches a predefined value. If the passwords match, you can proceed with the desired action, otherwise, display an error message.

<?php
if(isset($_POST['password'])) {
    $password = $_POST['password'];
    
    // Define the correct password
    $correct_password = 'secret';

    if($password == $correct_password) {
        echo "Password correct! Proceed with the action.";
    } else {
        echo "Incorrect password. Please try again.";
    }
}
?>

<form method="post">
    <label for="password">Enter password:</label>
    <input type="password" name="password">
    <button type="submit">Submit</button>
</form>