Hello I am trying to create an audit log when a user enters through my log in.
The idea is that the audit.php creates a log.txt and add user history when a user logs in.
audit.php:
<?php
function logger($log){
if(!file_exists('log.txt')){
file_put_contents('log.txt','');
}
$ip = $_SERVER['REMOTE_ADDR']; //Client IP
$time = date('m/d/y h:iA',time());
$contents = file_get_contents('log.txt');
$contents .= "$ip\t$time\t$log\r";
file_put_contents('log.txt',$contents);
}
?>
I am Trying to implement this into my login code.
login.php:
if ($_SERVER[ 'REQUEST_METHOD' ] == 'POST')
{
$usernane = $_POST['username'];
$password = ($_POST['password' ]);
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND password = ? LIMIT 1");
$stmt->execute(array($usernane, $password));
$checkuser = $stmt->rowCount();
$user = $stmt->fetch();
if ($checkuser === 0){
}else if($checkuser === 1){
$_SESSION[ 'user' ] = $user['username'];
$_SESSION[ 'type'] = $user['type'];
if($user['type'] == 1){
header('location:Admin.php');
}else{
I tried implementing it in this portion of the code.
It comes up with the error " Uncaught Error: Call to undefined function logger()"
Any help is appreciated!
$log = "User Entered The Home Page";
logger($log);
header('location:Home.php');
}
}
}