Is it possible to pass parameters to a htaccess-protected page to send login credentials from a form?
It is not possible to pass parameters directly to a htaccess-protected page to send login credentials from a form. The htaccess authentication is handled by the web server before any server-side code, such as PHP, is executed. To send login credentials from a form, you would typically handle the form submission in a separate PHP script that validates the credentials and then redirects the user to the protected page if the credentials are correct.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
// Validate the credentials
if ($username == 'admin' && $password == 'password') {
// Redirect to the protected page
header('Location: protected-page.php');
exit;
} else {
echo 'Invalid credentials';
}
}
?>
<form method="post" action="">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit">Login</button>
</form>