How can PHP be used to create a login area that redirects each password to a different webpage?

To create a login area that redirects each password to a different webpage, you can use a PHP script that checks the entered password and redirects the user accordingly. You can store the passwords and corresponding redirect URLs in an associative array or database. When a user enters a password, the script will compare it with the stored passwords and redirect the user to the corresponding webpage if there is a match.

<?php
// Define an associative array with passwords and corresponding redirect URLs
$passwords = array(
    'password1' => 'page1.php',
    'password2' => 'page2.php',
    'password3' => 'page3.php'
);

// Check if a password is submitted
if(isset($_POST['password'])){
    $enteredPassword = $_POST['password'];
    
    // Check if the entered password matches any of the stored passwords
    if(array_key_exists($enteredPassword, $passwords)){
        $redirectUrl = $passwords[$enteredPassword];
        header("Location: $redirectUrl");
        exit;
    } else {
        echo "Invalid password";
    }
}
?>

<form method="post" action="">
    <label for="password">Password:</label>
    <input type="password" name="password" id="password">
    <button type="submit">Login</button>
</form>