2016-04-25 139 views
0

我有一个生成头像的脚本。这里是我的结构:如何限制访问我的网站的脚本为他人?

-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 

如何我可以将该脚本专门用于我自己的网站并禁止其他人使用它吗?

回答

3

将脚本放置在Web根目录之外。

scripts 
-MakeAvatar.php 
public (or whatever you call your webroot) 
-img 
-index.php 

这意味着www.site.com转到index.php文件,但您无法浏览到从浏览器的脚本。 您可以通过../scripts/MakeAvatar.php(来自index.php)。

+0

@stack这实际上是一个行业标准。如果你进入MVC或框架,你会发现我们倾向于尽我们所能从用户那里尽可能地隔离网站。回答你的问题,不。即使有人可以看到你如何称呼脚本(他们不能),除非他们有服务器访问(他们不会),他们看不到脚本。 – amflare