2016-12-24 34 views
1

我需要上傳很多屬於不同客戶&的圖像也是保密的。 Codeigniter已用於後端。Codeigniter:如何保護公共訪問和搜索引擎的圖像

的圖像具有路徑www.example.com/customerID/image.jpg

我已閱讀關於保持根級別&以上的圖像的方法,然後將它們複製暫時當用戶的需求。但它看起來非常複雜,因爲如果用戶突然關閉瀏覽器,則需要在每次加載頁面時執行其他檢查以刪除以前未刪除的圖像。

還有哪些其他有效的選擇?

編輯: 我不是在尋找一般性的建議,但實際上如何實現在codeigniter中只使用代碼。

+0

參考:http://www.naturefocused.com/articles/image-protection.html –

回答

2

您可以使該文件夾無法從網絡訪問(例如,將文件夾放置在htdocs外部或添加.htaccess規則)。

創建一個處理私人圖像的所有請求的PHP腳本。如果用戶被授權

-check如果用戶進行身份驗證
檢查以查看請求的圖像打開圖像並將其打印到瀏覽器
(需要設置:此腳本必須做到以下幾點正確的HTTP頭,以確保內容被視爲圖像)

演示

getimage.php

if (LoggedInUserCanAccessThisFile())//this is optional user define function as requirement if you want that only login user can see image then with the help of your session variables or cookies you can return this function true or false 
    { 
    $file = 'privatedir/image.jpg'; 
    $type = 'image/jpeg'; 
    header('Content-Type:'.$type); 
    header('Content-Length: ' . filesize($file)); 
    readfile($file); 
    exit(); 
    } 

home.php/otherpage.php

<img src="getimage.php" /> 

(你可以使用SRC = 「getimage.php?用戶id = 123」,進入getimage.php並檢查該用戶登錄或不顯示圖像)

(也可以使用SRC = 「getimage.php?用戶ID = 123 & imgfilename = image3.jpg」 動態圖像的代碼,並進入getimage.php作爲

$file = 'privatedir/'.$_GET["imgfilename"];