I've just got a new computer, and I've been setting up PHP/MySQL/databases etc... I think I'm just about there, except it's thrown this curveball. My login script was working fine, but now it's spitting the following warning (which messes up the JSON).
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 'Antarctica/Macquarie' for 'EST/10.0/no DST' instead in .../php/login.php on line 47
My code obviously uses date()
and is working in the live version and on the old machine. I get two warnings for the following two lines of code:
$date = date("ymd");
$this_year = date("y");
My research (see here) suggests that the behaviour of these functions depends on php.ini .
So should I change php.ini on the new machine, or am I using some kind of deprecated method, and should I ditch date()
altogether?
Thanks.
The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.
The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts. See PHP's list of supported timezones to find the names of all possible timezones you can use for the date.
The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.
The date() function formats a local date and time, and returns the formatted date string.
You don't need to change the php.ini file if you use date_default_timezone_set()
. Just set it to the timezone you will be working in.
Something like this should go in a config file or on the page where you're working with dates (if it is only one page):
date_default_timezone_set('America/Los_Angeles');
It's not an exception, it's a warning that is probably popping up now because your error reporting settings on the new machine are different from the old one.
I would suggest to follow the suggestion in the warning, and use date_default_timezone_set()
to set a time-zone in the scripts where you need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With