Category Archives: PHP

[PHP][PHPExcel] PHPExcel讀檔案記憶體不夠 Fatal Error Allowed memory size of xxx

前幾天在處理客戶Case 時發現,PHPExcel 在讀檔案的時候 會造成 php Fatal Error Allowed memory size of xxx 的問題,
客戶的檔案 約有 10000 record , 5 MB 左右,當初在開發時 只有 500 record ,500KB 所有病沒有產生這樣的問題。
稍微用了一下google 查資料 ,發現 PHPExcel 似乎會產生大量的迴圈 ,這部份可以用 var_dump 一下 物件即可以知道
不過他吃了 快要1G 的 memory   有哪家的公司主機允許這樣子的吃法XD。
後來發現似乎有解 ,只要加入 setReadDataOnly(true) 就可以解決了

Continue reading “[PHP][PHPExcel] PHPExcel讀檔案記憶體不夠 Fatal Error Allowed memory size of xxx” »

[PHP] 取得副檔名的方法

Continue reading “[PHP] 取得副檔名的方法” »

[PHP] [Array] 如何刪除索引陣列中的值

如何刪除索引陣列中的值。

 

[PHP][Linux] PHP安全性加強 抵擋 駭客 存取 linux 下的 /etc/password

近日公司部份客戶發現有被hacker 嘗試的 存取 linux 下的 /etc/passowrd 檔,請參照下圖

attachments/200806/9567811677.jpg

很明顯的看到是在要取得 password 檔的內容,另外在從MySQL資料庫中也發現到

看到這幾筆資料 , 就覺得有問題了:

| 44 | `cat /etc/passwd`                                                                  | y     |
| 45 | cat /etc/passwd                                                                    | y     |
| 46 | ;cat /etc/passwd;                                                                  | y     |
| 47 | |cat /etc/passwd                                                                   | y     |
| 48 |  cat /etc/passwd                                                                   | y     |
| 49 | <cat /etc/passwd                                                                   | y    |
| 50 | ../../../../../../../../etc/passwd                                                 | y      |
| 51 | ../../../../../../../../etc/passwd                                                 | y      |
| 52 |  ../../../../../../../../etc/passwd                                                | y      |
| 53 | ../../../../../../../../etc/passwd .html                                           | y    |
| 54 | ../../../../../../../../etc/passwd .jpg                                            | y     |
| 55 | .\\./.\\./.\\./.\\./.\\./.\\./etc/passwd                                           | y      |
| 56 | /etc/passwd                                                                        | y      |
| 57 | /./././././././etc/passwd                                                          | y      |
| 58 | ..\..\..\..\..\..\..\..\etc/passwd                                                 | y      |
| 59 | ../..//../..//../..//../..//../..//../..//../..//../..//etc/passwd                 | y      |
| 60 | ../…/.././../…/.././../…/.././../…/.././../…/.././../…/.././etc/passwd | y      |
| 61 | <../../../../../../../../etc/passwd                                                | y     |
 

 
由於是前人遺留下來的程式….所以還是需要花點時間去處理。
處理的方式有很多種
 
1.在寫程式時針對一些欄位需要在html 端檢查機制,例如 email 手機等..
   以增強安全性
 
 
2.不過厲害一點的hacker 或 hacker 軟件還是知道怎麼避開html 端的檢查機制
    還是需要程式端進行處理,原則上 linux 下的 /etc 目錄 (/etc 下是存放 linux 的config 設定檔 ) 是不被 web owner access 的,利用這個特點去檢查
    下面代碼會檢查 是否有/etc 目錄 有的話會強制 將 值回傳 boolean false
 

 
3.另外如果 已知一些變數的 型態 為特定的 例如 int 、boolean 、string 的話
   請將這些值強制的型態強制轉換
    
  例如有一個url http://www.iware.com.tw/pro.php?cid=20   
    
  程式寫法為 (int)$_REQUEST[cid]
  或
  intval($_REQUEST[cid])
 
 
  (int)$_REQUEST[cid] 的值會變成0 這樣也可以抵擋攻擊

[序][PHP] PHP 程式設計標準

PHP 程式設計標準

Continue reading “[序][PHP] PHP 程式設計標準” »

[PHP] [PHP100例] No.44 調用文本文件內容

PHP 100 實例,第44題。

Continue reading “[PHP] [PHP100例] No.44 調用文本文件內容” »

[PHP] [PHP100例] No.43 訪問文件常見屬性

PHP 100 實例,第43題。

Continue reading “[PHP] [PHP100例] No.43 訪問文件常見屬性” »

[PHP] [PHP100例] No.42 讀取文件內容

PHP 100 實例,第42題。

Continue reading “[PHP] [PHP100例] No.42 讀取文件內容” »

[PHP] [PHP100例] No.41 打開本地或者遠程文件

PHP 100 實例,第41題。

Continue reading “[PHP] [PHP100例] No.41 打開本地或者遠程文件” »

[PHP] [PHP100例] No.40

PHP 100 實例,第40題。

Continue reading “[PHP] [PHP100例] No.40” »