2016-04-25 54 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