The task is to make authorization on jQuery + PHP + SQL.

Javascript:

$(document).ready(function(){ $("#form").submit(function(e){ e.preventDefault(); if($("#loginText").val()!=""&&$("#passwordText").val()!=""){ $.ajax({ url:"login.php", method:"POST", data: $(this).serialize(), success:function(html){toVote(html);} }); } else{ $("#error").html("Не введен логин или пароль"); } }); var toVote=function(html){ if(html=="error"){ $("#error").html("Логин или пароль введен неверно"); $("#loginText").val(""); $("#passwordText").val(""); } else{ window.location = '/project/voting.html'; } }; }); 

The question is as follows. How to make it so that the voting.html page cannot be accessed by an unregistered user simply by typing the URL address? Ie how to determine the user's login when calling html pages through AJAX?

  • I see only one solution: when you call a page through AJAX, then send another request to the PHP page, where it will respond: whether it is logged in or not. And that would not directly enter, it is necessary to do through .htaccess - Yuri

1 answer 1

and what prevents to keep the status "logged in / logged out" in $ _SESSION and check there when processing ajax request?