エラーが出る理由と解決方法

このQ&Aのポイント
  • dateやmktimeやgetdateなどを使うとエラーが出る理由は、システムのタイムゾーン設定が正しくされていないためです。
  • 解決方法としては、date.timezoneの設定を行うか、date_default_timezone_set()関数を使用することです。
  • また、サーバーのタイムゾーンを指定することで問題を解決することも可能です。
回答を見る
  • ベストアンサー

dateやmktimeやgetdateなどでエラー

<?php print "a"; echo rand(1,10); ?> とかはちゃんと表示されるのですが、 dateやmktimeやgetdateなどを使うとエラーが出てしまいます。 サンプルコードは参考書通りなので間違っていないと思うのですが、 サーバー側の問題なのでしょうか。サーバーはapache2.4でローカルで使っています。 <?php echo date('c', mktime(1, 2, 3, 4, 5, 2006)); ?> Warning: mktime() [function.mktime]: 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 'Asia/Tokyo' for '9.0/no DST' instead in C:\apache\htdocs\a.php on line 4 Warning: date() [function.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 'Asia/Tokyo' for '9.0/no DST' instead in C:\apache\htdocs\a.php on line 4 2006-04-05T01:02:03+09:00 <?php $today = getdate(); print_r($today); ?> Warning: getdate() [function.getdate]: 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 'Asia/Tokyo' for '9.0/no DST' instead in C:\apache\htdocs\a.php on line 2 Array ( [seconds] => 6 [minutes] => 44 [hours] => 23 [mday] => 11 [wday] => 6 [mon] => 2 [year] => 2012 [yday] => 41 [weekday] => Saturday [month] => February [0] => 1328971446 )

  • PHP
  • 回答数1
  • ありがとう数2

質問者が選んだベストアンサー

  • ベストアンサー
  • kmee
  • ベストアンサー率55% (1857/3366)
回答No.1

正確にはエラーじゃなく「警告(warning)」です。 で、メッセージは読みました? 「It is not safe to rely on the system's timezone settings」で検索したら、原因と対処がいくらでも見つかりますよ。 最近追加されたようなので、古い参考書には載っていないのかもしれません。

kiseki777
質問者

お礼

検索し解決策を見つけました。 php.iniでTimeZoneを設定する必要があり、 「Module Settings」セクションで ;date.timezone = を date.timezone = "Asia/Tokyo" と変更しました。 無事に全て表示されました。 有難うございました。

関連するQ&A

  • Strict Standards: date()   mkdate()

    PHP5を使っています。 error_reporting(E_STRICT); をつけると、2つのエラー?が画面に表示されます。 これが表示されるということは、何か原因があると思います。 phpのコードで根本から直したいので、対処方法をご存知の方、教えてください。 error_reportingをコメントとかは、したくないです。 (1) Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable 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 'Asia/Tokyo' for 'JST/9.0/no DST' (2) Strict Standards: mktime() [function.mktime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable 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 'Asia/Tokyo' for 'JST/9.0/no DST'

    • ベストアンサー
    • PHP
  • Xampp でWarning

    Mac OSX10.6 でXampp を使い始めました 下記の様なWarningがでます Warning: date() [function.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. php.iniの date.timezone="Asia/Tokyo" にしたら 直ったとネットでは書いていましたが やってみても直りません 何か対策はありますか? よろしくお願いいたします。

    • ベストアンサー
    • PHP
  • phpinfo();でtimezoneが設定されていないというエラーが

    phpinfo();でtimezoneが設定されていないというエラーが出てしまいます。 phpはバージョン5.3.2です。 エラーは Warning: phpinfo() [function.phpinfo]: 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 'Asia/Tokyo' for '9.0/no DST' instead in C:\inetpub\wwwroot\phpinfo.php on line 2 と書いてあったのでphp.iniを確認しましたが、 date.timezone = Asia/Tokyo という記述は確かにありました。 Loaded Configuration Fileのパスも編集しているものと同じでした。 phpinfo();を書く前に date_default_timezone_set('Asia/Tokyo'); とするとエラーは出ません。 原因がよくわからなくて困っています。教えていただけないでしょうか。

    • 締切済み
    • PHP
  • PHPのエラーについて

    <?php session_start(); require('../dbconnect.php'); if (!isset($_SESSION['join'])) { header('Loction: index.php'); } if (!empty($_POST)) { //登録処理 $sql = sprintf('INSERT INTO test_users SET name="%s", email="%s", password="%s", created="%s"', mysql_real_escape_string($_SESSION['join']['name']), mysql_real_escape_string($_SESSION['join']['email'], mysql_real_escape_string(sha1($_SESSION['join']['password'])), date('Y-m-d H:i:s')); mysqli_query($sql) or die(mysqli_error()); var_dump($sql); unset($_SESSION['join']); header('Location: thanks.php'); exit(); } ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> </head> <body> <form action="" method="post"> <input type="hidden" name="action" value="submit"> <div><a href="index.php?action=rewrite">&laquo;&nbsp;書き直す</a> <input type="submit" value="登録"> </div> </form> </html> これを実行すると Warning: Unknown: 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 /home/****/www/join2/check.php on line 15 Parse error: syntax error, unexpected ';' in /home/kazu94/www/join2/check.php on line 15 このようなエラーがでます(汗 どこが間違っているのか教えてください(泣

    • 締切済み
    • PHP
  • PHPの会員登録システムのエラーについて

    現在よくわるPHPの教科書という本を参考に、会員登録システムをつくっています。 しかし、本に書いてある内容をそのまま書いて実行してみてもエラーがでてきます。 そこでいろいろとネットで調べてみて以下のようなコードになりました。 <?php //$error = array('name'=>'', 'email'=>'', 'password'=>''); session_start(); if (!empty($_POST)) { if ($_POST['name'] === '') { $error['name'] = 'blank'; } if ($_POST['email'] === '') { $error['email'] = 'blank'; } if (strlen($_POST['password']) < 4) { $error['password'] = 'length'; } if ($_POST['password'] === '') { $error['password'] = 'blank'; } if (empty($error)) { $_SESSION['join'] = $_POST; header('Location: http:./check.php'); exit(); } } ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>会員登録</title> </head> <body> <form action="" method="POST"> ユーザーID<input type="text" name="name" value="<?php print isset($_POST['name']) ? htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8'):"";?>" /> <?php if ($error['name'] === 'blank') { ?> <p class="error">*ユーザーIDを入力してください</p> <?php } ?> メールアドレス<input type="text" name="email" value="<?php print isset($_POST['email']) ? htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8'):"";?>" /> <br> <?php if ($error['email'] === 'blank') { ?> <p class="error">*メールアドレスを入力してください</p> <?php } ?> パスワード<input type="password" name="password"> <br> <?php if ($error['password'] === 'blank') { ?> <p class="error">*パスワードを入力してください</p> <?php } ?> <?php if ($error['password'] === 'length') { ?> <p class="error">*パスワードは4文字以上で入力してください</p> <?php } ?> <input type="submit" value="登録"> </form> </body> </html> しかしこれでもエラーがでます。以下のエラー Warning: Unknown: 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 /home/****/www/join/index.php on line 39 Parse error: syntax error, unexpected ':' in /home/kazu94/www/join/index.php on line 39 誰かこのエラーの謎を解いてください お願いします(泣)

    • 締切済み
    • PHP
  • 自分のサーバーでのみstrtotime() とdate(のエラーが表示されます。

    Warning: strtotime() [function.strtotime]: Called with an empty time parameter. in Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in 【WinXp、PHP4】 自分のサーバーでPHPを実行した場合にのみこの様な エラーが表示されます。 また、エラーは出ていますが正常に動作しています。 この表示のみをなくすにはどのように 設定を変えればいいのでしょうか?

    • 締切済み
    • PHP
  • 【至急】MySQLのエラーを解消したいのですが?

    データを間違って消してしまい、サーバーにデータを バックアップ復活したのですが、以下の様なエラーが生じており、 困っております。 MySQLのエラーを解消したいのですが?、知識がなく、どうすればいいのでしょうか? ・1)Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL Server Host '0net' (1) in /ファイルパス/ファイル.php on line 7 ・2)Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /ファイルパス/ファイル.php on line 8 ・3)Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /ファイルパス/ファイル.php on line 8 ・4)Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /ファイルパス/index.php on line 5 ・5) Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /ファイルパス/index.php on line 5 ・6) Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /アフィルパス/index.php on line 6 ・7) Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /ファイルパス/index.php on line 6

  • function()を初めて使いました。エラー。

    かなり初歩的な質問をさせていただきます。 初めてfunction関数を使ったのですが、下記のようなエラーが出ました。 Warning: array_reverse() [function.array-reverse]: The argument should be an array in E:\Web\Chat2\chat\logpage.php on line 99 Warning: array_reverse() [function.array-reverse]: The argument should be an array in E:\Web\Chat2\chat\logpage.php on line 100 Warning: array_reverse() [function.array-reverse]: The argument should be an array in E:\Web\Chat2\chat\function.php on line 38 Warning: flock() expects parameter 1 to be resource, boolean given in E:\Web\Chat2\chat\function.php on line 41 Warning: fputs(): supplied argument is not a valid stream resource in E:\Web\Chat2\chat\function.php on line 48 Warning: flock() expects parameter 1 to be resource, boolean given in E:\Web\Chat2\chat\function.php on line 49 Warning: fclose(): supplied argument is not a valid stream resource in E:\Web\Chat2\chat\function.php on line 50 チャットを作っていて、何度も使う文をfunctionでまとめて、別ファイルに保存し、 requireで呼び出して、str();で使うとこうなりました。 function load(){ $log_data = "./data/log".$_GET['id'].".cgi"; $log_file = file($log_data); $member_data = "./data/member".$_GET['id'].".cgi"; $member_file = file($member_data); } このような形で使っているのですが、何かfunctionを使うにあたって注意などがあれば教えていただけませんか?

    • 締切済み
    • PHP
  • PHPiniレベルで、strtotime()とdate()のエラー表示させない方法

    Warning: strtotime() [function.strtotime]: Called with an empty time parameter. in Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in 【WinXp、PHP4】 自分のサーバーでPHPを実行した場合にのみこの様な エラーが表示されます。 また、エラーは出ていますが正常に動作しています。 この表示のみをなくすにはどのように "PHPiniの設定"を変えればいいのでしょうか? ちなみにスクリプトレベルでの回避策は、 error_reporting(E_ERROR); $number=10/0; とする事で応急処置としては完了しております。 また、Function内のコーディング変更は必要ありません。 他のサーバーでは正常に動作しています。 引数もありません。 ご自分のサーバーでPHPを設定された経験のある方がいらっしゃいましたら、何卒どうぞ宜しくお願い致します。

    • ベストアンサー
    • PHP
  • エラーの意味

    本当に困り果てています。 この警告の意味を教えてください。 Warning: fopen(test.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/html/練習プログラム/test_kanryou.php on line 17 Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/html/練習プログラム/test_kanryou.php on line 18 誰か詳しい方がいれば、教えていただきたいです。 よろしくお願いします。

    • ベストアンサー
    • PHP