Good morning! I have some problem with HTTP authentication with PHP. As I found in different posts, after the form's submit I tried this PHP code:
PHP
<?php
$us = 'name';
$pswd = 'pass';
function verify($a, $b) { return ($a==$us && $b==$pswd);};
$user = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if(!isset($user) || verify($user, $password)==false) {
header('WWW-Authenticate: Basic realm="MyRealm"');
header('HTTP/1.1 401 Unauthorized');
exit;
}
else{
echo 'Correctly authenticated';
}
?>
When I click the submit botton form from HTML a popup appears asking me (again) username and password. Why? I think that in some ways I've to set the PHP_AUTH_USER in $_SERVER with the value in the input, but I don't know how.
I think that I've done a mistake when I send the data from the form because I'm still using the post method. What method I have to use?
HTML
<br>
<form method="post" action="page.php">
<input type="text" name="user">
<input type="password" name="password">
<input type="submit">
</form>
<br>
I never did it before, any tips on how check data on server side or something else are welcome!