Below are two functions that I'm positive are written correctly.
Problem is, that there are times, when my Session does not time out, but the AJAX request returns 403 error (also happens with some other functions without any pattern).
Stack overflow is filled with questions asking for help with this problem, but I did not find any really good answers:
- Redirection + 403 error
- Http 403 - Forbidden error
- 403 Forbidden Error
- getting 403 forbidden in ajax
- etc
Question(s):
- How can you cause a 403 error by code?
- If I have multiple asynchronous AJAX requests running at the same time, can it cause a 403 error? ( I do fire several (max 5) ajax requests at one time )
- Do I have to set something about directory listing in .htaccess if I want to call AJAX requests in the form of relative_path/action instead of relative_pat/action.php?
- 403 can be caused, by my Session expiring, right?
AJAX:
var root = "/test_tool";
function isLoggedIn()
{
// return if the user is in the sign in window
if ( window.location == "http://localhost" + root +"/" )
{
return;
}
var output = "";
$.ajax (
{
url: root + "/users/isLoggedIn",
context: document.body,
async: true
} ).done( function( result )
{
output = result;
if ( output == "" )
{
alert( " You have been logged out. " );
window.location = "http://localhost" + root +"/";
}
});
}
(CAKE) PHP:
public function isLoggedIn()
{
$this->autoRender = false;
return ( $this->Auth->user('username') != null );
}