Do AJAX requests retain PHP Session info?

前端 未结 8 891
情书的邮戳
情书的邮戳 2020-11-28 18:52

If I had a user logged onto my site, having his id stored in $_SESSION, and from his browser he clicked a \'Save\' button which would make an AJAX request to th

相关标签:
8条回答
  • 2020-11-28 19:51

    It is very important that AJAX requests retain session. The easiest example is when you try to do an AJAX request for the admin panel, let's say. Of course that you will protect the page that you make the request to, not to accessible by others who don't have the session you get after administrator login. Makes sense?

    0 讨论(0)
  • 2020-11-28 19:58

    The answer is yes:

    Sessions are maintained server-side. As far as the server is concerned, there is no difference between an AJAX request and a regular page request. They are both HTTP requests, and they both contain cookie information in the header in the same way.

    From the client side, the same cookies will always be sent to the server whether it's a regular request or an AJAX request. The Javascript code does not need to do anything special or even to be aware of this happening, it just works the same as it does with regular requests.

    0 讨论(0)
提交回复
热议问题