How can PHP be used to send a file to a client after a password input?

To send a file to a client after a password input, you can create a PHP script that checks if the correct password is entered by the user. If the password is correct, the script can use headers to force the browser to download the file. You can store the password in a secure manner, such as using a hashed version in a database.

<?php
$correctPassword = "your_password_here";

if(isset($_POST['password']) && $_POST['password'] === $correctPassword) {
    $file = 'path_to_your_file.pdf';
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    readfile($file);
    exit;
} else {
    echo "Incorrect password. Please try again.";
}
?>