I am creating a access log in PHP where I am storing the logged-in username , userip and userlogged-in time inside my sql server database
I want to add one more field filename into that, I am taking everything from previous pages using sessions but however, I am unable to figure out how do I take filename from the previous page
I am sharing my code too. Any help would be highly appreciated.
my code for creating access log in php and storing it inside sql-server database is
session_start();
include 'database_connection.php'
$uname = $_SESSION["user"] ;
echo $uname;
function getUserIP()
{
// Get real visitor IP behind CloudFlare network
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
return $ip;
}
$user_ip = getUserIP();
echo $user_ip; // Output IP address [Ex: 177.87.193.134]
$currentDate = date('Y-m-d g:i:s');
echo $currentDate;
$sql = "insert into ACCESS_LOGOFUSERS(ALU_USERNAME,ALU_IP,ALU_CREATEDON)
VALUES('$uname','$user_ip','$currentDate')";
$res = sqlsrv_query($conn,$sql);
session_destroy();
?>
my file name code which is stored on the previous page is
$fileName = basename($_FILES["fileToUpload"]["name"]);
I am unable to figure out how shall I take the $filename to another page with the help of the session so that I can also add the below code to my existing code
$query=sqlsrv_query("insert into user_action(file_name)values('$file_name')");