2014-10-09 77 views
1

我是新來的PHP。我想在每個月的特定日期重定向用戶。比較日期從當前日期和重定向頁面後比較

我試過下面的代碼,但它不工作。

<? 
date_default_timezone_set('Asia/kolkata'); 

$date = date('Y-m-d'); 
$dateblock = date ('d', strtotime($date)); 

if ($dateblock ="2" || $dateblock ="5" || $dateblock ="9" || $dateblock ="11" || $dateblock ="13" || $dateblock ="16" || $dateblock ="18" || $dateblock ="21" || $dateblock ="23" || $dateblock ="25" || $dateblock ="27" || $dateblock ="29" || $dateblock ="30") { 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>404 Page Not Found</title> 
</head> 
<body> 

<center> 
    <img src="images/sorry.png" /> 
</center> 

</body> 
</html> 

    <?}else{ 

echo "Redirecting You..... Please Wait..."; 
header('Refresh: 3;url=pagexyz.php'); 

}?> 

基本上我想只顯示在一個月中日期pagexyz.php除了在上述語句中使用日期。

或者

是否有任何其他的方法來隱藏在每個月的特定日期pagexyz.php

回答

1

或者,你也可以使用一個in_array()功能如下:

<?php 
date_default_timezone_set('Asia/Kolkata'); 
          //^big letter K 
$date = date('Y-m-d'); 
$dateblock = date ('d', strtotime($date)); 
$restricted_days = array(2,5,9,11,13,16,18,21,23,29,30); 
?> 

<?php if(in_array($dateblock, $restricted_days)): ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>404 Page Not Found</title> 
    </head> 
    <body> 

    <center> 
    <img src="images/sorry.png" /> 
    </center> 

    </body> 
</html> 
<?php else: ?> 
    <h1>Redirecting!! Please wait!!!</h1> 
    <meta http-equiv="refresh" content="3; url=http://www.google.com" /> 
<?php endif; ?> 
+0

是的,它的工作....謝謝。我可否知道,我的代碼中的哪個因素造成了問題? – chplab 2014-10-09 05:38:19

+0

@chplab錯誤發生在'date_default_timezone_set()'上,因爲你在'Kolkata'裏面輸入了小寫字母'k',所以它對內部值嚴格要求。我打開錯誤報告 – Ghost 2014-10-09 06:11:25