I would like to save full session logs in text per each day. here is my code to create file and save log.
session_start();
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: index.php");
//Write action to txt log
$log = "User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
"Attempt: ".($result[0]['success']=='1'?'Success':'Failed').PHP_EOL.
"User: ".($_SESSION['SESS_USER_ID']).PHP_EOL.
"User Type: ".($_SESSION['SESS_USER_TYPE']).PHP_EOL.
"-------------------------".PHP_EOL;
//-
file_put_contents('./log_'.date("j.n.Y").'.txt', $log, FILE_APPEND);
//exit();
}
$expiry = 60;//session expiry required after 30 mins
if (isset($_SESSION['LAST']) && (time() - $_SESSION['LAST'] > $expiry)) {
session_unset();
session_destroy();
header("location: logout.php");
}
$_SESSION['LAST'] = time();
Its not creating any file so can anyone help me to save session login time, logout time & session activity in text file in root directory