2015-08-03 109 views
0

在我的數組中,我有非常長的變量用作安全令牌,以防止沒有權限訪問PHP服務器的人員。 但是,如果變量通過安全牆,我希望能夠記錄數據以檢查不良動作,但似乎無法找到排除某些變量的方法,以防止我的日誌文件太大並頻繁旋轉。PHP json_encode();排除數組

logissue("User ".$authname." is now preforming ".json_encode($data)); 

收益並記錄這個龐大的數據大塊..

66.***.***.** 2015/08/03 06:28:52 User Nickoplier is now preforming {"Validate":"[email protected]*au8c8.....","Action":"message","auth":":ZzWh[a....","Parameter1":"2933***","Parameter2":"hello :D","Parameter3":"just a test"} 

是否可以排除日誌「驗證」和「權威性」?

回答

3

是,只需添加:

unset($data['Validate'], $data['auth']); 

線陣列轉換成JSON之前。您可以根據需要使用盡可能多的數組鍵。你甚至可以排除子鍵子陣列:unset($data['stuff']['more-stuff']['field'])

這將刪除鍵,所以更好的辦法是換一個函數內部的整個組件,並在通過$data

+1

注:''unset' '刪除那個條目,所以確保你以後不需要它們 – jmattheis