Im doing a project in school, and i need to control that the user has the right to access one of the pages. All functions need to go trough Ajax.
My problem is with the callback for the Ajax. Struggled for a couple of days, but cant seem to fix it. If i skip the Ajax, it works. But i need to get it to work with ajax. I dont know what to use as a callback, i've tried alot of solutions, none working.
What happens is that anyone can reach the page, no matter Session.
Jquery:
<script>
$(window).load( function checkUser() {
$.post('calling_check_staff.php',
function(data){
$(). html(data); // I think the problem is here?????
});
});
</script>
calling_check_staff.php
<?php
session_start();
include ("php-classes/classUsers.php");
// Calling the class User and controlling that the visitor is logged in
$user = new User();
if($user->loggedIn()) {
}
?>
PHP class
public function loggedIn() {
// Control, accessed page via login page.
if(isset($_SESSION["username"]) && $_SESSION["username"] != null) {
} else { header("location:index.php");
} }