I have a link tag structured like this:
<a href="<?php echo base_url().'dashboard' ?>" class="check_session">Home</a>
Upon clicking the "Home" link, it should navigate to the dashboard. At the dashboard page, I want to check if a session exists. If there is an active session, continue to the dashboard. Otherwise, log out.
The JavaScript code I am using for this functionality is as follows:
$(".check_session").click(function() {
$.ajax({
url: base_url+"shared/check_session/"+Math.random()+new Date().getTime(),
success: function(response){
if(response == 'out')
{
alert('Please login');
window.location.href = base_url + "logout";
}
}
});
});
However, I am facing an issue where the check session function is not being called when the Home link is clicked.
Can anyone help me find a solution to resolve this problem?
Thank you in advance!