跳到主要內容

發表文章

目前顯示的是 8月, 2012的文章

CEntOS 上 PHP 5.3 的時區設定問題

最近將原本 Fedora 12 的主機更換成 CEntOS 6.3 版,在這個版本中的 PHP 預設為 5.3.3 版。放上先前撰寫的程式,當有使用到 Date 函數時會出現下面的警告訊息: "PHP Notice: It is not safe to rely on the system's timezone settings, You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier" PHP 5.3 現在需要我們在 php.ini 中設定 timezone 的資訊,或是在使用 date() 函數前先做  date_default_timezone_set() 的設定。 因為是自己的主機,因此我趨向更改 php.ini 設定即可。打開 /etc/php.ini 設定,大約在 943 行的地方有 timezone 的設定項目內容如下: [Date] ; Defines the default timezone used by the date functions ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone ; date.timezone = 因為我主機的時區位置是 Taipei 時間,取消 date.timezone 前面的註解符號,並在等號後方加入 "Asia/Taipei"(PHP 的時區可以參考官方 List of Supported Timezones )修改後項目內容如下: [Date] ; Defines the default timezone used by the date functions ; http://www.php.net/manual/en/datetime.co