Solve the "Itisnotsafetorelyonthesystem" problem of php.

Source: Internet
Author: User
Tags what php
: This article describes how to solve the "Itisnotsafetorelyonthesystem" stimezonesettings of php. if you are interested in the PHP Tutorial, refer to it. This article describes how to solve the "It is not safe to rely on the system's timezone settings" problem in php. For more information, see

If php. ini is not correctly configured when PHP5.3 or later is used, the PHP date function is incorrect. In the past, many old PHP programming tutorials did not mention this issue, so many readers may be confused. the following I will tell you three ways to solve this problem.
"PHP 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 'utc' for '8. 0/no DST 'instead in"

In fact, when using functions such as date () in PHP 5.1.0, if the timezone settings are incorrect, the E_NOTICE or E_WARNING information will be generated each time the time function is called. In PHP 5.1.0, date. the timezone option is disabled by default. no matter what PHP command is used, the Greenwich Mean Time is used. However, it seems that PHP 5.3 will forcibly throw this error if it is not set, to solve this problem, just localize it.

1. use date_default_timezone_set () in the page header to set date_default_timezone_set ('prc'); // echo in the East eight time zone
Date ('Y-m-d H: I: s ');

2. use ini_set ('date. timezone ', 'Asia/Shanghai') in the page header ');

3. modify php. ini (if it is a windows system, the file is in the C drive, Windows directory, and if the system is installed on the C drive ). Use Notepad to open php. ini and find date. timezone. remove the semicolon and change it to: date. timezone = "Asia/Shanghai"
Restart php or http services (such as apache2 or iis!

You can choose one of the above three methods. The third method is recommended for small editors, so you do not need to add additional code each time.


The above describes how to solve the "It is not safe to rely on the system's timezone settings" problem in php, including the following content, if you are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.