Ajax redirect if return false
I have all the code done for the login and session done now I want on each page that requires the user to be logged in to check and if false redirect.
class.php
- public function check_session() {
- session_start();
- if (isset($_SESSION['user_id'])) {
- return true;
- }
- else {
- return false;
- }
- }
session.php
- <?php
- /* Includes */
- include 'database.php';
- include 'class.php';
- $session = new Session($pdo);
- if($session->check_session()) {
- return true;
- }
- else {
return false;
}
session.js
- /*
- Redirect if not logged in
- */
- $('document').ready(function() {
$.ajax({
type : 'POST',
url : 'dist/php/session.php',
data : data,
success : function(response) {
if(response=="true"){
}
else{
window.location.href="log-in.html";
}
});
});
});
It is not redirecting so what is wrong?