it works....... but now the $_POST['re_auth'] is always set so it is calling authenticate() function over and over an do on,
so i tried to unset it with
unset($_POST['re_auth']);
but guess what....... it does not work,
can you explain to me which is the logical sequence of this script and if am i using the header properly
<?php
if (isset($_POST['re_auth'])) {
authenticate();
}
function authenticate() {
unset($_POST['re_auth']);
header('WWW-Authenticate: Basic realm="Test Authentication System"');
header('HTTP/1.0 401 Unauthorized');
echo "You must enter a valid login ID and password to access this resource\n";
exit;
}
//* validete if the login exist using imap server*/
function if_has_mail_account($login,$pass){
if (($devuelve = @imap_open("{ip port}INBOX",$login,$pass,OP_HALFOPEN))!=FALSE)
{
return 1;
}
return 0;
}//end of the function
if((if_has_mail_account($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))==1) {
echo "<p>Welcome: {$_SERVER['PHP_AUTH_USER']}<br>";
echo "<form action='{$_SERVER['PHP_SELF']}' METHOD='POST'>\n";
echo "<input type='submit' name='re_auth' value='Re Authenticate'>\n";
echo "</form></p>\n";
echo "<input type='submit' name='re_auth' value='Re Authenticate'>\n";
echo "</form></p>\n";
}
else authenticate();
?>
sorry if i made a stupid mistake