Hello all, nice to meet you.
So i have a problem to add logs for when logout in my web project, and the problem is like this:
I have a code to record activity log like this :
$name = $this->session->userdata('UserProfile');
$logdata = array(
'userid'=>$name->username,
'activity'=>'Logout BO',
'param'=>''
);
$this->base->log_activity($logdata);
and i want it to put and running only when this jquery is clicked (this code below is for logout), so i add the code and put it like this:
$(".js__logout").on("click",function(){
window.location.href = localStorage.getItem("SystemUrl"); //back to login menu
<?php
$name = $this->session->userdata('UserProfile');
$logdata = array( 'userid'=>$name->username,
'activity'=>'Logout BO',
'param'=>''
);
$this->base->log_activity($logdata);
?>
});
And the problem is, when i refresh the webpage and not yet do logout (button with class js__logout isnt yet clicked), i see the program was sent that logdata to my database.
So everytime i going to this webpage (example: user activity log) , its everytime too it will record logactivity “Logout BO” to my database.
Here’s the example :
Am i wrong with calling that php code? Or is that must be a condition to deal with it? Please help me
Thank you so much