PHP 配置:依赖系统的时区设置是不安全的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2213608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:32:11  来源:igfitidea点击:

PHP Configuration: It is not safe to rely on the system's timezone settings

phptimezone

提问by Ole Media

Here a weird one. I just upgrade to php 5.3.0 and since the upgrade I'm getting the following warning:

这里有一个奇怪的。我只是升级到 php 5.3.0,升级后我收到以下警告:

Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are requiredto 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 'America/Chicago' for 'CST/-6.0/no DST'

警告:getdate() [function.getdate]:依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们为“CST/-6.0/no DST”选择了“America/Chicago”

After looking in various forums, everybody says that to solve the problem, all you have to do is edit the date zone in the php.ini and restart Apache.

看了各种论坛,大家都说要解决这个问题,你要做的就是编辑php.ini中的日期区并重新启动Apache。

It did not work for me.

它对我不起作用。

I tried

我试过

date.timezone="America/New_York"

date.timezone=America/New_York

date.timezone="US/Central"

Restarted apache after I made the change.

更改后重新启动 apache。

Since I still have the older version of php install, I even made sure that I'm editing the php.ini that the current version of php uses at the time to load

由于我仍然安装了旧版本的 php,我什至确保我正在编辑当前版本的 php 加载时使用的 php.ini

/usr/local/php5/lib/php.ini

/usr/local/php5/lib/php.ini

Still getting the warning.

仍然收到警告。

Any suggestions?

有什么建议?

Thanks for taking the time.

感谢您抽出宝贵的时间。

回答by Vaughany

Tchalvak, who commented on the original question, hit the nail on the head for me. I've been editing (I use Debian):

对原始问题发表评论的 Tchalvak 为我击中了钉子。我一直在编辑(我使用 Debian):

/etc/php5/apache2/php.ini

...which had the correct timezone for me and was the only .ini file being loaded with date.timezone within it, but I was receiving the above error when I ran a script through Bash. I had no idea that I should have been editing:

...它对我来说有正确的时区,并且是唯一一个在其中加载 date.timezone 的 .ini 文件,但是当我通过 Bash 运行脚本时收到了上述错误。我不知道我应该编辑:

/etc/php5/cli/php.ini

as well. (Well, for me it was 'as well', for you it might be different of course, but I'm going to keep my Apache and CLI versions of php.ini synchronised now).

以及。(嗯,对我来说它是'同样',对你来说当然可能会有所不同,但我现在要保持 php.ini 的 Apache 和 CLI 版本同步)。

回答by cichy

回答by Garvin

I happened to have to set up Apache & PHP on two laptops recently. After much weeping and gnashing of teeth, I noticed in phpinfo's output that (for whatever reason: not paying attention during PHP install, bad installer) Apache expected php.ini to be somewhere where it wasn't.

最近我碰巧不得不在两台笔记本电脑上设置 Apache 和 PHP。在多次哭泣和咬牙切齿之后,我在 phpinfo 的输出中注意到(无论出于何种原因:在 PHP 安装过程中没有注意,安装程序错误)Apache 希望 php.ini 位于它不存在的地方。

Two choices:

两种选择:

  1. put it where Apache thinks it should be or
  2. point Apache at the true location of your php.ini
  1. 把它放在 Apache 认为它应该放在的地方,或者
  2. 将 Apache 指向 php.ini 的真实位置

... and restart Apache. Timezone settings should be recognized at that point.

...并重新启动Apache。此时应识别时区设置。

回答by codex

Open your .htaccess file , add this line to the file, save, and try again :

打开您的 .htaccess 文件,将此行添加到文件中,保存并重试:

php_value date.timezone "America/Sao_Paulo"

This works for me.

这对我有用。

回答by selangk

try this, it works for me.

试试这个,它对我有用。

date_default_timezone_set('America/New_York');

In the actual file that was complaining.

在抱怨的实际文件中。

回答by Ashutosh Nigam

Please modify your index.php as follows:

请修改您的 index.php 如下:

require_once($yii);
$app = Yii::createWebApplication($config);
Yii::app()->setTimeZone('UTC');
$app->run();

回答by user1613163

Obviously I'm a little out of season on this question but for the benefit of the next sufferer: I just had this problem and in my case (in contrast to OP who tried the same without success) the fix was to revise php.ini, changing

显然我在这个问题上有点不合时宜,但为了下一个受害者的利益:我刚刚遇到了这个问题,在我的情况下(与尝试相同但没有成功的OP相反)修复是修改php.ini, 改变

date.timezone = America/New York

to

date.timezone = America/New_York

That is adding the underscore.

那就是添加下划线。

回答by amercader

Check for syntax errors in the php.ini file, specially beforethe Date paramaters, that prevent the file from being parsed correctly.

检查 php.ini 文件中的语法错误,特别是Date 参数之前,防止文件被正确解析。

回答by Vipin Pal

I modified /etc/php.ini

我修改了/etc/php.ini

[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezonedate.timezone =('Asia/kolkata')

[日期] ; 定义日期函数使用的默认时区;http://php.net/date.timezonedate.timezone =('亚洲/加尔各答')

and now working fine.

现在工作正常。

Vipin Pal

贵宾朋友

回答by SirNikkolas

You may have forgot to remove the semicolon to uncomment that line. For the date.timezone = "US/Central"line, be sure that there's no semicolon in front of that line.

您可能忘记删除分号以取消注释该行。对于该date.timezone = "US/Central"行,请确保该行前没有分号。