严格的标准时区错误


Strict standards timezone error

更改主机后我遇到错误:在我的Wordpress网站上。

严格的标准: date((:依赖系统的是不安全的时区设置。您需要使用 date.时区设置或 date_default_timezone_set(( 函数。如果您使用了任何这些方法,你仍然收到这个警告,你很可能时区标识符拼写错误。我们选择了"欧洲/柏林"作为改为"CET/1.0/无夏令时"/homepages/42/d545555785/htdocs/lifetips.ro/baby-gender-predictor.php在第 69 行

严格的标准: date((:依赖系统的是不安全的时区设置。您需要使用 date.时区设置或 date_default_timezone_set(( 函数。如果您使用了任何这些方法,你仍然收到这个警告,你很可能时区标识符拼写错误。我们选择了"欧洲/柏林"作为改为"CET/1.0/无夏令时"/homepages/..../htdocs/lifetips.ro/baby-gender-predictor.php 在线76

严格的标准: strtotime((:依赖系统的是不安全的时区设置。您需要使用 date.时区设置或 date_default_timezone_set(( 函数。如果您使用了任何这些方法,你仍然收到这个警告,你很可能时区标识符拼写错误。我们选择了"欧洲/柏林"作为改为"CET/1.0/无夏令时"/homepages/..../htdocs/lifetips.ro/baby-gender-predictor.php 在线82

严格的标准: strtotime((:依赖系统的是不安全的时区设置。您需要使用 date.时区设置或 date_default_timezone_set(( 函数。如果您使用了任何这些方法,你仍然收到这个警告,你很可能时区标识符拼写错误。我们选择了"欧洲/柏林"作为改为"CET/1.0/无夏令时"/homepages/..../htdocs/lifetips.ro/baby-gender-predictor.php 在线82

在此大约 200 行代码中生成:

<?php
/* This predictor is your for free by EverydayVBabies.com. You have no obligations for anything - you can modify, redistribute, sell it or whatever you want to do.
We will appreciate if you don't remove the link at the bottom, but that's not required. */
/* Feel free to modify the CSS and the texts below. - no problem at all. Just don't touch the PHP code or the specual codes which are surrounded with %% unless you know what you are doing. */
error_reporting(E_ALL&(~E_NOTICE));
@session_start();
?>
<style type="text/css">
.calculator_div
{
    font-family:verdana, arial, sans-serif;
    border:2pt solid #FF44FF;
    padding:25px;
    width:250px;
    margin:auto;
}
label
{
    display:block;
    float:left;
    width:150px;        
}
</style>
<?php
// present the calculator table as multi-dimentional PHP array
$table=array(
    "18"=>array("",'f','m','f','m','m','m','m','m','m','m','m','m'),
    "19"=>array("",'m','f','m','f','f','m','m','m','m','m','f','f'),
    "20"=>array("",'f','m','f','m','m','m','m','m','m','f','m','m'),
    "21"=>array("",'m','f','f','f','f','f','f','f','f','f','f','f'),
    "22"=>array("",'f','m','m','f','m','f','f','m','f','f','f','f'),
    "23"=>array("",'m','m','f','m','m','f','m','f','m','m','m','f'),
    "24"=>array("",'m','f','m','m','f','m','m','f','f','f','f','f'),
    "25"=>array("",'f','m','m','f','f','m','f','m','m','m','m','m'),
    "26"=>array("",'m','f','m','f','f','m','f','m','f','f','f','f'),
    "27"=>array("",'f','m','f','m','f','f','m','m','m','m','f','m'),
    "28"=>array("",'m','f','m','f','f','f','m','m','m','m','f','f'),
    "29"=>array("",'f','m','f','f','m','m','m','m','m','f','f','f'),
    "30"=>array("",'m','f','f','f','f','f','f','f','f','f','m','m'),
    "31"=>array("",'m','f','m','f','f','f','f','f','f','f','f','m'),
    "32"=>array("",'m','f','m','f','f','f','f','f','f','f','f','m'),
    "33"=>array("",'f','m','m','m','f','f','f','m','f','f','f','m'),
    "34"=>array("",'m','f','m','f','f','f','f','f','f','f','m','m'),
    "35"=>array("",'m','m','f','m','f','f','f','m','f','f','m','m'),
    "36"=>array("",'f','m','m','f','m','f','f','f','m','m','m','m'),
    "37"=>array("",'m','f','m','m','f','m','f','m','f','m','f','m'),
    "38"=>array("",'f','m','f','m','m','f','m','f','m','f','m','f'),
    "39"=>array("",'m','f','m','m','m','f','f','m','f','m','f','f'),
    "40"=>array("",'f','m','f','m','f','m','m','f','m','f','m','f'),
    "41"=>array("",'m','f','m','f','m','f','m','m','f','m','f','m'),
    "42"=>array("",'f','m','f','m','f','m','f','m','m','f','m','f'),
    "43"=>array("",'m','f','m','f','m','f','m','f','m','m','m','m'),
    "44"=>array("",'m','m','f','m','m','m','f','m','f','m','f','f'),
    "45"=>array("",'f','m','m','f','f','f','m','f','m','f','m','m')
);
$new_years=array("2014"=>"January 31, 2014", "2015"=>"February 19, 2015", "2016"=>"February 9, 2016",
"2017"=>"January 28, 2017", "2018"=>"February 16, 2018", "2019"=>"February 5, 2019",
"2020"=>"January 25, 2020");
if(!empty($_POST['calculator_ok']))
{
    // save in session to be used when the link "calculate again" is clicked
    foreach($_POST as $key=>$var) $_SESSION["calc_".$key]=$var;
    
    // calculate mother's lunar age
    if (date("n") <= $_POST['month'])
    {
        // conceived this year
        $year_conceived=date("Y")-1;        
    }
    else 
    {
        $year_conceived=date("Y");      
    }
    
    $new_year=$new_years[$year_conceived];      
    
    // should I add 1 or 2 years to age?
    if(strtotime($new_year)>strtotime($year_conceived."-".$_POST["month"]."-01"))   
    {
        $addition=1;
    }
    else $addition=2;
    
    $lunar_age=$_POST['age']+$addition;
    
    // calculate the result     
    $result=$table[$lunar_age][$_POST['month']];
    
    $gender=($result=='f')?"<span style='"font-size:21px;font-weight:bold;color:pink;'">Girl</a></span>":"<span style='"font-size:21px;font-weight:bold;color:lightblue'">Boy</span>";
    //the result is here
    ?>
    <div class="calculator_div">
    <p align="center">Your lunar age of conception is <b><?=$lunar_age?></b>.</p>
    <p align="center">You kid is most likely to be a <?=$gender?></p>
    <p align="center"><a href="http://<?=$_SERVER['HTTP_HOST'];?><?=$_SERVER['REQUEST_URI']?>">Calculate again</a></p>
    </div>
    <?php
}
else
{
    //the calculator comes here
    ?>
    <div class="calculator_div">
    <form method="post">
    <p><label>Your age of conception:</label> <select name="age">
    <?php for($i=16;$i<=43;$i++): 
    if($i==$_SESSION['calc_age']) $selected='selected';
    else $selected='';
    echo "<option $selected value='$i'>$i</option>";
    endfor ?>
    </select></p>
    
    <p><label>Month of conception:</label> <select name="month">
    <option value="1" <?if($_SESSION['calc_month']==1) echo "selected"?>>January</option>
    <option value="2" <?if($_SESSION['calc_month']==2) echo "selected"?>>February</option>
    <option value="3" <?if($_SESSION['calc_month']==3) echo "selected"?>>March</option>
    <option value="4" <?if($_SESSION['calc_month']==4) echo "selected"?>>April</option>
    <option value="5" <?if($_SESSION['calc_month']==5) echo "selected"?>>May</option>
    <option value="6" <?if($_SESSION['calc_month']==6) echo "selected"?>>June</option>
    <option value="7" <?if($_SESSION['calc_month']==7) echo "selected"?>>July</option>
    <option value="8" <?if($_SESSION['calc_month']==8) echo "selected"?>>August</option>
    <option value="9" <?if($_SESSION['calc_month']==9) echo "selected"?>>September</option>
    <option value="10" <?if($_SESSION['calc_month']==10) echo "selected"?>>October</option>
    <option value="11" <?if($_SESSION['calc_month']==11) echo "selected"?>>November</option>
    <option value="12" <?if($_SESSION['calc_month']==12) echo "selected"?>>December</option>
    </select></p>
    <div style="text-align:center;clear:both;"><input type="submit" value="Calculate!"></div>
    <input type="hidden" name="calculator_ok" value="1">
    </form> 
    <p style="text-align:center;font-size:11px;"><a href="http://everydaybabies.com">Baby Photo Contest</a></p>
    </div>
    <?php
}
?>
这正是

错误所说的:您在使用date()函数时没有提供时区,根据 PHP 的说法,这可能会导致时间错误。

事实上,在这一行中:

if (date("n") <= $_POST['month'])

调用date()函数,但未设置时区。

如果您可以控制 php.ini 设置,只需添加该行

date.timezone=<your_default_timezone_identifier>

否则,如果您无法修改 php.ini,只需添加该行

date_default_timezone_set("<your_default_timezone_identifier>");

在页面顶部。

这些不是错误,只是警告。根据您的位置以 php.ini 为单位设置合适的 date.时区值,然后重新启动您的 Web 服务器。