gpt4 book ai didi

php - fwrite 的 777 权限是否危险?

转载 作者:可可西里 更新时间:2023-11-01 00:44:33 25 4
gpt4 key购买 nike

我正在测试我的 php 表单并将所有请求记录到一个单独的文件中。目的是查明该表单是否被用于垃圾邮件并希望将其消除。

当使用 fwrite() 记录请求时,使用 777 权限是否危险或不必要?有什么选择?

最佳答案

您只需要应用程序正在运行的用户的权限就可以写入文件。有时管理员能够读取文件也很方便。除此之外,没有人需要访问。因此,0640 是此类文件最合理的权限。

特别是,没有人需要执行 文件,这是用0777 设置的位之一。只有目录需要执行位。 (还有可执行程序,但这里没有。)

0640 = user/owner read/write, group read only, other no access
0777 = user/owner read/write/execute, group read/write/execute, other read/write/execute

umask对于获得正确的权限非常有用。您可以使用 umask 来设置权限模板,而不是创建具有明确权限的文件。由于目录需要可执行权限而文件不需要,umask 将比显式设置它们更明智地屏蔽不同类型文件的权限。例如,在您的情况下:

umask(027); // Owner permissions unchanged, Group permissions mask 2, drop all other permissions
fopen('foo', 'w', 0777); // Creates file with *0640* permissions, because of mask
mkdir('bar', 0777); // Creates dir with *0750* permissions, because of mask

关于php - fwrite 的 777 权限是否危险?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23473866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com