我有一个生成头像的脚本。这是我的结构:
-folder1
-scripts
-MakeAvatar.php
-img
-avatar
我在其他页面中使用它,如下所示:
$name = 'anything';
$hash = md5($name);
$input = "http://localhost/folder1/scripts/MakeAvatar.php?hash=$hash";
$output = "../../folder1/img/avatar/".$name.".jpg";
file_put_contents($output, file_get_contents($input));
如您所见,每个人都可以访问此脚本并制作头像:
http://localhost/folder1/scripts/MakeAvatar.php?hash=$hash
我怎样才能将该脚本专用于我自己的网站并禁止其他人使用它?
将脚本放在 Web 根目录之外。
scripts
-MakeAvatar.php
public (or whatever you call your webroot)
-img
-index.php
这意味着 www.site.com 转到索引.php,但您无法从浏览器导航到脚本。但是,您可以通过执行以下操作: ../scripts/MakeAvatar.php
(来自索引.php)。