The code blow was used for authenticatin for a page (it is snippet of whole page but the main idea is here):
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"MX Administration\"");
header("HTTP/1.0 401 Unauthorized");
exit;
}
else {
session_start();
if( $_SERVER['PHP_AUTH_USER'] == $login && md5($_SERVER['PHP_AUTH_PW'] ) == $password ){
if( $_SESSION['adm'] == '' && empty($_POST) ){
header("Location: whmcs.php");
exit;
}
elseif( $_SESSION['adm'] == '' && !empty($_POST) ){
if( $_POST['login'] == $login_in && md5($_POST['password']) == $password_in ){
$_SESSION['adm']="OK";
}
else{
header("Location: whmcs.php?do=message");
exit;
}
}
else{
$_SESSION['adm']="OK";
}
}
else{
header("WWW-Authenticate: Basic realm=\"MX Administration\"");
header("HTTP/1.0 401 Unauthorized");
echo ":)\n";
exit;
}
}
?>
Now when I have transfered this code to another server, it does not authenticate, it always asks for username, password. I guess it is because of php version, php config. What you think what may br the reason. (I am sure that I am writing the correct username and password.)
Most likely the reason is CGI API used to run PHP scripts.
You have to either change API to mod_php or change hosting or change HTTP auth to sessions