How can I restrict access to some PHP pages only from pages within my website?

后端 未结 6 969
北海茫月
北海茫月 2020-12-16 05:08

I have in my website a PHP page which retrieves data from my database to be presented in my website. This page is called via AJAX. How can I restrict the access to it only f

6条回答
  •  心在旅途
    2020-12-16 05:40

    Similar to @ZZ-coder answer, but you can do it with cookies.

    1) Set the cookie on the server (hash of "ip-address + secret"), a non-persistent cookie that lasts for 1 session only, after user logs in.

    2) Check the cookie on the server during AJAX requests (because cookies are being sent with AJAX requests as well)

    This is similar to @ZZ-coder's answer, but you can skip the JS part completely.

提交回复
热议问题