OK, well, you have numerous ways to do this. The quickest is to write all of the login attempts to a text file called "attempts.txt", which you could view/periodically download and see all of the people who've made attempts at logging in.
The way I made it [of course, format can be changed] is the following:
User: {{username}}
Password: {{password}}
Date/Time: {{date&&time}}
Here's the finished code:
PHP Code:
/* No user serviceable parts below this point. */
$php_self = $_SERVER['PHP_SELF'];
/* Sanitize variables: we should only be getting $user and $password from the form. */
$submit = $_POST['submit'];
$user = '';
$password = '';
if ($_GET['user']) {
$user = $_GET['user'];
$password = $_GET['password'];
}
if ($_POST['user']) {
$user = $_POST['user'];
$password = $_POST['password'];
}
session_start();
/* Check login/password pairs until we find one that is correct, or show login form again. */
$loginsuccessful = FALSE;
foreach ($authorization as $loginpair) {
if (($user == $loginpair[0]) && ($password == $loginpair[1])) {
$_SESSION['user'] = $user;
$_SESSION['password'] = $password;
$loginsuccessful = TRUE;
}
if (($_SESSION['user'] == $loginpair[0]) && ($_SESSION['password'] == $loginpair[1])) {
$loginsuccessful = TRUE;
}
}
if ($loginsuccessful === TRUE) {
/* User is logged in, go about our merry way. */
echo $loginmsg;
} else {
$timestamp = date();
/* User didn't match any of our valid logins, kick them back to the form. */
$loginmsg = "Invalid username or password.";
$stringData = "
Username: ".$user."
Password: ".$password."
Date/Time: ".$timestamp.";
$myFile = "attempts.txt"; // name of file
$fh = fopen($myFile, 'a') or die("can't open file"); // open file
fwrite($fh, $stringData); // append to file
fclose($fh); // close file
require($indexphp);
exit;
}
Please note that you need to make sure that attempts.txt already exists on the same path of this php script.
HTH
Bookmarks