2013年12月27日 星期五
2013年12月17日 星期二
PHP 檔案操作
如何對檔案進行 唯一 的資料讀寫
fopen 開檔
flock LOCK_EX 鎖檔
fread filesize 讀入檔案
rewind 移動檔案 point
ftruncate 0 清空檔案
fwrite 寫入檔案
flock LOCK_UN 解鎖
fclose 關檔
程式範例
fopen 開檔
flock LOCK_EX 鎖檔
fread filesize 讀入檔案
rewind 移動檔案 point
ftruncate 0 清空檔案
fwrite 寫入檔案
flock LOCK_UN 解鎖
fclose 關檔
程式範例
$handle = fopen("file.txt","r+");
//Lock File, error if unable to lock
if(flock($handle, LOCK_EX)) {
$count = fread($handle, filesize("file.txt")); //Get Current Hit Count
$count = $count + 1; //Increment Hit Count by 1
rewind($handle); //Move file point
ftruncate($handle, 0); //Truncate the file to 0
fwrite($handle, $count); //Write the new Hit Count
flock($handle, LOCK_UN); //Unlock File
} else {
echo "Could not Lock File!";
}
//Close Stream
fclose($handle);
2013年10月22日 星期二
2013年10月21日 星期一
利用 htaccess 保護網頁
利用 htaccess 保護網頁(目錄) 需進行登入,才有辦法檢視
這功能很常用,每次用都 google , 今天就醬它給它記錄下來
需求說明:
我要將 /var/www/phpMyadmin/ 此目錄設定需登入才有辦法瀏覽
在該目錄底下新增 .htaccess 檔案
貼上以下內容 ( 使用者名稱,以 shazi 為例 )
輸入密碼(2次)
完成!!
這功能很常用,每次用都 google , 今天就醬它給它記錄下來
需求說明:
我要將 /var/www/phpMyadmin/ 此目錄設定需登入才有辦法瀏覽
在該目錄底下新增 .htaccess 檔案
nano .htaccess
貼上以下內容 ( 使用者名稱,以 shazi 為例 )
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /var/www/phpMyadmin/apasswords
Require user shazi
再進行建立 密碼檔 apasswords
htpasswd -c /var/www/phpMyadmin/apasswords shazi
輸入密碼(2次)
完成!!
訂閱:
文章 (Atom)