“phpinfo():依靠系统的时区设置是不安全的...” [英] "phpinfo(): It is not safe to rely on the system's timezone settings..."

查看:2446
本文介绍了“phpinfo():依靠系统的时区设置是不安全的...”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当运行Blue.box(FreeSwitch PBX的前端)的php安装脚本时,我收到有关时区失败的错误。



然后我开始挖掘。我不知道现在发生了什么。但是这是我所拥有的:



我在我的public_html目录中创建了一个info.php文件,其中包含一行:



我收到这个错误并输出


警告:phpinfo():依靠不安全系统的时区
设置。您需要 使用date.timezone设置或
date_default_timezone_set()函数。如果您使用这些
方法中的任何一种,并且您仍然收到此警告,那么您很可能
错误地标记了时区标识符。我们在
'EDT / -4.0 / DST'上选择'America / New_York',而不是在/home/0default/public_html/info.php行
1




 日期/时间

支持启用
Olson时区数据库版本0.system
时区数据库内部
默认时区America / New_York

指令本地值主值
date.default_latitude 31.7667 31.7667
date.default_longitude 35.2333 35.2333
date。 sunrise_zenith 90.583333 90.583333
date.sunset_zenith 90.583333 90.583333
date.timezone美国/纽约州美国/纽约州



我创建了一个文件/etc/php.d/timezone.ini,内容如下:

  [root @ mercury php.d]#cat timezone.ini 
;默认时区
date.timezone ='America / New_York'
[root @ mercury php.d]#

我可以将时区更改为America / Los_Angeles(例如),在apache重新启动后,date.timezone字段正确更改。



但是我仍然收到错误。



任何想法?



---附加说明 - -



如果我更改了/etc/php.d/timezone.ini文件:

  [root @ mercury php.d]#cat timezone.ini 
;默认时区
date.timezone ='America / Los_Angeles'

我可以导致更改到info.php输出:



date



警告:phpinfo():依赖不安全在系统的时区设置。您需要 使用date.timezone设置或date_default_timezone_set()函数。如果您使用任何这些方法,并且您仍然收到此警告,您很可能拼写时区标识符。我们在第1行的/home/0default/public_html/info.php中选择'EDT / -4.0 / DST'的'America / New_York'

 启用日期/时间支持
Olson时区数据库版本0.system
时区数据库内部
默认时区America / New_York

指令本地值主值
date.default_latitude 31.7667 31.7667
date.default_longitude 35.2333 35.2333
date.sunrise_zenith 90.583333 90.583333
date.sunset_zenith 90.583333 90.583333
date.timezone美国/ Los_Angeles美国/ Los_Angeles

---附加说明---



对于正在学习的人(正如我),加载了几个.ini文件。在info.php输出中:

 配置文件(php.ini)路径/ etc 
加载配置文件/ home /0default/etc/php5/php.ini
扫描此目录以获取额外的.ini文件/etc/php.d
解析为/etc/php.d/curl.ini / etc的其他.ini文件/php.d/dom.ini,/etc/php.d/fileinfo.ini,/etc/php.d/gd.ini,/etc/php.d/imap.ini,/etc/php.d/json .ini,/etc/php.d/mbstring.ini,/etc/php.d/mysql.ini,/etc/php.d/mysqli.ini,/etc/php.d/odbc.ini,/ etc / php.d / pdo.ini,/etc/php.d/pdo_mysql.ini,/etc/php.d/pdo_odbc.ini,/etc/php.d/pdo_pgsql.ini,/etc/php.d/pdo_sqlite。 ini,/etc/php.d/pgsql.ini,/etc/php.d/phar.ini,/etc/php.d/snmp.ini,/etc/php.d/sqlite3.ini,/ etc / php .d / timezone.ini,/etc/php.d/wddx.ini,/etc/php.d/xmlreader.ini,/etc/php.d/xmlrpc.ini,/etc/php.d/xmlwriter.ini ,/etc/php.d/xsl.ini,/etc/php.d/zip.ini

第一个加载的是/etc/php.ini,然后是加载配置文件,然后是扫描此目录文件。



所以例如,应该能够在不同的默认时区中创建一些php网站。将主默认设置为/etc/php.ini,然后允许每个网站具有加载...部分中标识的不同时区。然后,如果有人担心任何覆盖,主人可以再次使用/etc/php.d文件覆盖。



我尝试更改date.timezone 在三个位置的每一个中,并成功更改date.timezone,如info.php所示...但它不会修改默认时区值,这是导致错误的值。



另一个注意事项,我正在运行的.php脚本实际上是Blue.box,FreeSwitch的前端。所以...我改变了.php脚本犹豫了。

解决方案

你有两个选择。


  1. 在使用任何日期函数之前,调用此函数 date_default_timezone_set(America / New_York) / p>


  2. 编辑通常位于 /use/local/php/php.ini 的php.ini文件,更改 date.datetimezone 条目。



While running a php installation script for Blue.box (front end to FreeSwitch PBX), I get this error about a timezone failure.

Then I start digging. I'm not sure what is going on at this point. But here is what I have:

I created an info.php file in my public_html directory that contains a single line:

And I get this error and output

Warning: 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 'America/New_York' for 'EDT/-4.0/DST' instead in /home/0default/public_html/info.php on line 1

date/time

     support    enabled
    "Olson" Timezone Database Version   0.system
    Timezone Database   internal
    Default timezone    America/New_York

    Directive   Local Value Master Value
    date.default_latitude   31.7667 31.7667
    date.default_longitude  35.2333 35.2333
    date.sunrise_zenith 90.583333   90.583333
    date.sunset_zenith  90.583333   90.583333
    date.timezone   America/New_York    America/New_York

I created a file /etc/php.d/timezone.ini with the following:

[root@mercury php.d]# cat timezone.ini
; default time zone
date.timezone='America/New_York'
[root@mercury php.d]#

I'm able to change timezone to America/Los_Angeles (for example), and after apache reboot the "date.timezone" field changes correctly.

But I still get the error.

Any ideas?

--- Additional note ---

If I change the /etc/php.d/timezone.ini file:

[root@mercury php.d]# cat timezone.ini
; default time zone
date.timezone='America/Los_Angeles'

I can cause a change to the info.php output:

date

Warning: 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 'America/New_York' for 'EDT/-4.0/DST' instead in /home/0default/public_html/info.php on line 1

date/time support   enabled
"Olson" Timezone Database Version   0.system
Timezone Database   internal
Default timezone    America/New_York

Directive   Local Value Master Value
date.default_latitude   31.7667 31.7667
date.default_longitude  35.2333 35.2333
date.sunrise_zenith 90.583333   90.583333
date.sunset_zenith  90.583333   90.583333
date.timezone   America/Los_Angeles America/Los_Angeles

--- Additional note ---

For those who are learning (as I am), several .ini files are loaded. In the info.php output:

Configuration File (php.ini) Path   /etc
Loaded Configuration File   /home/0default/etc/php5/php.ini
Scan this dir for additional .ini files /etc/php.d
Additional .ini files parsed    /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/odbc.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_odbc.ini, /etc/php.d/pdo_pgsql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/pgsql.ini, /etc/php.d/phar.ini, /etc/php.d/snmp.ini, /etc/php.d/sqlite3.ini, /etc/php.d/timezone.ini, /etc/php.d/wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlrpc.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini

The first one loaded is /etc/php.ini, then the "loaded configuration file", then the "scan this dir" files.

So for example, one should be able to create a number of php web sites in different default timezones. Set the master default in /etc/php.ini, then allow each of the web sites to have a different time zone as identified in the "loaded..." section. Then, if one is concerned about any overrides, the master can again override with the /etc/php.d files.

I've tried changing the "date.timezone" in each of the three locations, and successfully change the date.timezone as displayed by the info.php... but it does not modify the "Default timezone" value, which is the value that is causing the error.

Another note, the .php script that I am running is actually Blue.box, a front end to FreeSwitch. So... I am hesitant in changing that .php script.

解决方案

You have 2 options.

  1. Call this function date_default_timezone_set("America/New_York") before using any date functions.

  2. Edit the php.ini file usually located at /use/local/php/php.ini and change the date.datetimezone entry.

这篇关于“phpinfo():依靠系统的时区设置是不安全的...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆