<?

//-----------------------------------
// Http doğrulaması için login penceresi açar.
function AuthMsg() {
  
header('WWW-Authenticate: Basic realm="Doğrulama Örneği"');
  
header('HTTP/1.0 401 Unauthorized');

?>
<HTML>
<HEAD>
    <TITLE>Doğrulama Örneği</TITLE>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-9">
</HEAD>

<BODY>
  <B>Sadece yetkili kullanıcının girişine izin verilmiştir.</B><BR>
</BODY>
</HTML>
<?

  
exit;
}

//-----------------------------------
// Kullanici yetkili degil ise http authentication login penceresi açar.
function Authenticate() {
  GLOBAL 
$PHP_AUTH_USER$PHP_AUTH_PW$pwfile;

  
$auth=False;

  if(!empty(
$PHP_AUTH_USER) && !empty($PHP_AUTH_PW)) {
    
$rows=file($pwfile);
    
reset($rows);
    for(;
$row=current($rows);next($rows)) {
      
$fields=explode(":",$row);
      if(
$PHP_AUTH_USER==trim($fields[0]) && $PHP_AUTH_PW==trim($fields[1])) {
        
$auth=True;
        break;
      }
    }
  }

  if(!
$auth) {
    
AuthMsg();
    exit;
  }
}
//-----------------------------------
$pwfile='mylist';

if(!isset(
$act)) $act="";

if(
$act=="logout") {
  
AuthMsg();
  exit;
}

Authenticate();

echo 
"Hoşgeldiniz...<BR>";
echo 
"Şu anda <B>$PHP_AUTH_USER</B> kullanıcısı olarak bağlısınız.<BR>";
echo 
"Şifreniz <B>$PHP_AUTH_PW</B><BR>";
echo 
'<A HREF="'.$PHP_SELF.'?act=logout">Logout</A>';
?>