我是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 ,除了上述if语句中使用的日期。
或
有没有其他方法可以在每个月的特定日期隐藏 pagexyz.php ?
答案 0 :(得分: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; ?>