【问题标题】:Strict standards timezone error [duplicate]严格标准时区错误[重复]
【发布时间】:2015-02-06 00:17:03
【问题描述】:

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

严格标准:date():依赖系统的 时区设置。您需要使用 date.timezone 设置 或 date_default_timezone_set() 函数。如果您使用任何 这些方法,您仍然收到此警告,您很可能 时区标识符拼写错误。我们选择了“欧洲/柏林” 'CET/1.0/no DST' 代替 /homepages/42/d545555785/htdocs/lifetips.ro/baby-gender-predictor.php 在第 69 行

严格标准:date():依赖系统的 时区设置。您需要使用 date.timezone 设置 或 date_default_timezone_set() 函数。如果您使用任何 这些方法,您仍然收到此警告,您很可能 时区标识符拼写错误。我们选择了“欧洲/柏林” 'CET/1.0/no DST' 代替 /homepages/..../htdocs/lifetips.ro/baby-gender-predictor.php 上线 76

严格标准:strtotime():依赖系统的 时区设置。您需要使用 date.timezone 设置 或 date_default_timezone_set() 函数。如果您使用任何 这些方法,您仍然收到此警告,您很可能 时区标识符拼写错误。我们选择了“欧洲/柏林” 'CET/1.0/no DST' 代替 /homepages/..../htdocs/lifetips.ro/baby-gender-predictor.php 上线 82

严格标准:strtotime():依赖系统的 时区设置。您需要使用 date.timezone 设置 或 date_default_timezone_set() 函数。如果您使用任何 这些方法,您仍然收到此警告,您很可能 时区标识符拼写错误。我们选择了“欧洲/柏林” 'CET/1.0/no DST' 代替 /homepages/..../htdocs/lifetips.ro/baby-gender-predictor.php 上线 82

在这个 ca 中生成。 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
}
?>

【问题讨论】:

标签: php syntax-error


【解决方案1】:

这正是错误所说的:您正在使用 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>");

在页面顶部。

【讨论】:

    【解决方案2】:

    这些不是错误,只是警告。根据您的位置在 php.ini 中设置suitable date.timezone 值并重新启动您的网络服务器。

    【讨论】:

      猜你喜欢
      • 2011-10-07
      • 2013-09-15
      • 2015-01-10
      • 2016-12-11
      • 2012-01-24
      • 2013-12-10
      • 2016-12-11
      • 2013-07-03
      • 2014-04-24
      相关资源
      最近更新 更多