date() [function.date]: and strtotime() [function.strtotime]: errors

I am a school teacher and I use a couple of scripts that were written for me a few years ago. Their purpose is to select a name from a database in sequential order and then switch to the next name for the next day. Hope I said that right.

School is starting and a few days and I checked my site and the pages that use these scripts are kicking up some errors. I have looked at the problem and tried to find a solution but my lack of knowledge has me stumped. Below I have the errors and the code, can anyone tell me what to fix and how to do it. Assume I know nothing, because I don’t :smiley:

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 'America/Chicago' for   'CDT/-5.0/DST' instead in daily/index.php   on line 6
Warning:  strtotime() [function.strtotime]:   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/Chicago' for   'CDT/-5.0/DST' instead in daily/index.php   on line 7

[php]function getName($table = ‘names’, $date = ‘’) {
$date = empty($date) ? date(‘Y-m-d’) : $date;
$day = date(‘z’, strtotime($date));

$x = mysql_query("SELECT * FROM $table ORDER BY id");
$names = array();
while ($n = mysql_fetch_array($x))
    $names[] = $n['name'];

for ($x = 0; $x < $day; $x++) {
    $fname = array_shift($names);
    $names[] = $fname;
}

return $names[1];

}

$male = getName(‘male’);
$female = getName(‘female’);
$manager = getName();[/php]

You can fix this in several ways. Here they are, from more efficient (1) to less:

  1. In your php.ini find and edit this setting: date.timezone
    Example: date.timezone = “America/Los_Angeles”

  2. If you have no access to php.ini, you can set timezone using this function: date_default_timezone_set()
    Example:
    [php]

<?php // insert this line somewhere at top of your php script date_default_timezone_set("America/Los_Angeles"); ?>

[/php]

  1. Since this is just a warning and not actually error, you can turn warnings off in your php script, like this:
    [php]
<?php error_reporting(E_ALL ^ E_WARNING); ?>

[/php]

For list of timezones go here: http://www.php.net/manual/en/timezones.php

Thank you so much for the help. I was able to fix the warnings and get things running the way they should.

Sponsor our Newsletter | Privacy Policy | Terms of Service