WEB/システム/IT技術ブログ

PHPの日付関数「date()」と「strtotime()」で突然のwarning(さくらレンタルサーバ)

ある日突然、PHPの日付関数「date()」と「strtotime()」からワーニングメッセージが表示されるようになりました。
さくらレンタルサーバ上で個人で運用しているCMSを長らく放置していた私が悪いのですが。。

特にPHPの設定を変更したわけでもなく、気が付いたらそうなっていたわけで、明確な原因は不明です。
恐らくさくらレンタルサーバ側でセキュリティアップデートなどがあったのでしょう。
詳細は後ほど調べてみます。

さて、表示されたwarningメッセージは以下の通りです。

Warning: date(): 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. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /xxx/xxx/xxx.php on line 10
Warning: strtotime(): 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. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /xxx/xxx/xxx.php on line 10

「プログラム側で任意のタイムゾーンを設定していないので、サーバシステムデフォルトのタイムゾーンを読み込んでいます。
任意で設定したほうがいいんじゃないですか?」
どうもこのようなことを警告しています。

そこで、php.iniを開き以下の1行を追加して、タイムゾーンを日本に設定します。

date.timezone = Asia/Tokyo

さくらレンタルサーバではコントロールパネルから設定できます。

今回こうなった原因を究明して、今後のプログラミングの時に気を付けなければいけませんね。
以上、緊急対策まで。

B!

Comment

コメントはありません

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Monthly Archives