Cookie approach should work. Another thing you can do is create a JSON page that returns true or false if the user is logged in. Then check that before your other code, if it is logged in, do what you do, if you don’t do anything else, maybe redirect to the Login page?
In jQuery, it looks something like this:
$.getJSON("/login/is_logged", function(json) {
if(!json.User.logged) {
window.location = '/login/form/';
}
});
The JSON page (url / login / is_logged) returns this:
{"User":{"logged":true}}
Here is a link to $. getJSON .
source
share