How to avoid UNLINK security risks in PHP?

后端 未结 7 1054
深忆病人
深忆病人 2021-01-12 18:59

I\'m using UNLINK with PHP and AJAX. I know that in this way is very dangerous, because everyone can delete any files. But I need to use AJAX

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 19:42

    You need to authenticate the user somehow.

    Your user needs to be authenticated with a username and a password.

    PHP session can be used to remember, and you should use a database table or a text file on the server to store file ownership information.

    Then, before unlinking anything, your logic should make sure that the currently "authenticated" user is the owner of the file.

提交回复
热议问题